Reputation: 798
I'mm creating an application which has many users which depend on each other.
For an example when a user signs up he inputs a reference number which he got from the person whom referred him to join so the process will continue like that until it forms a family tree hierarchy.
Here's another example great grandma would be the first user she'll pass her key to grandma (now grandma has two keys her own primary and reference key from great grandma) and grandma will pass her primary key to Mom. Now mom will have both (primary key and foreign key). If she decides to have child the process will continue in that Manner.
Now my question is how do I list this generation from great grandma to child in one View in firebase with so many keys involved ?
Code:
firebase.database().ref(users).orderBy('order by which key') ?
HTML:
<ul *ngFor="fam of family">
<li fam[key].username></li>which key goes in here....?
</ul>
Upvotes: 0
Views: 836
Reputation: 41294
I would create a family tree node with the list of all users:
families: {
"MTQ4MTUzNzc0NDYwNw": {
name: "smith",
users: {
"MTQ4MTUzNzc0NzU0Mw": true,
"MTQ4MTUzNzc0OTk0NQ": true,
"MTQ4MTUzNzc1MDg2OQ": true,
}
}
}
And users with child/parent properties
users: {
"MTQ4MTUzNzc0NzU0Mw": {
nick: "gran",
children: {
"MTQ4MTUzNzc0OTk0NQ": true,
"MTQ4MTUzODMzMDEyNQ": true,
},
parents: {
},
},
"MTQ4MTUzNzc0OTk0NQ": {
nick: "mom",
children: {
},
parents: {
"MTQ4MTUzNzc0OTk0NQ": true,
},
},
}
Then load family tree and process it's users on the client. If there are too many, you can keep JSON.stringify(client_side_family_tree)
in there. This is just data structure, you'll have to figure out UI...
PS. I know it's weird mom doesn't have children :p
Upvotes: 2