How do I store information about a many-to-many relationship without the concept of a join table in Firebase? -
my firebase app contains many-to-many relationship between groups , users. i'd store information when user joined group - how go without concept of join table?
i'm using firebase example reference: https://examples-k9xbyc0bhfwtlkdgfhs.firebaseio-demo.com/
do recommend doing this?
app: { groups: { group1: { members: { user1: { joindate: '2016-01-22t02:43:27.817z', iscreator: true }, user2: { joindate: '2016-01-23t02:43:27.817z', iscreator: false } } } }, users: { user1: { firstname: 'adam', lastname: 'soffer', groups: { group1: { joindate: '2016-01-22t02:43:27.817z', iscreator: true } } }, user2: { firstname: 'joe', lastname: 'shmoe', groups: { group1: { joindate: '2016-01-23t02:43:27.817z', iscreator: false } } } } }
the official structuring data guide great resource helping conceptual design this.
in general, it's best use nested data sparingly , flatten data possible.
you can represent same characteristics flatter structures.
membership: { user1: { group1: { joined: '2016-01-23t02:43:27.817z' }, group2: { joined: '2016-01-23t02:43:27.817z' } } }, groups: { group1: { creator: user1 }, group2: { creator: user1 } }, users: { user1: { firstname: 'adam', lastname: 'soffer' } }
we've used membership object manage many-to-many relationship of users , groups, allowing remove lot of nesting in groups , users fields.
assuming each group has 1 creator, it's possible move group objects, giving guarantee there can 1 creator , removing denormalized data our user objects.
Comments
Post a Comment