Reputation: 969
I'm currently trying to mentally work out how to construct my app's database structure based on it's function.
When a user registers an account to my Firebase backend they will be prompted to input information of their "Profile 1". Name, age, contact info and an image will be loaded into this profile.
They can then choose to create an additional profile consisting of exactly the same data: Name, age etc. They can continue to create further profiles.
So what I'm trying to figure out is now how to arrange my database to support this sort of structure. One user, multiple "set's" of data / Profiles. So when they open the app later on when they have multiple profiles created , they will be able to choose which one to load. Hence needing some sort of mechanism telling the database to load that specific set/profile of data.
Hope I made some sense out of this. Harder to explain than I thought. Thanks in advance!
Upvotes: 0
Views: 401
Reputation: 35659
How about this
users
uid_0
defaultProfile: "-YN9998ijssios"
profiles
-Yhnaiosioajsd
profileName: "profile 1"
name: "Bill"
age: "102"
contactInfo: "[email protected]"
-YN9998ijssios
profileName: "profile 2"
name: "Bill"
age: "102"
contactInfo: "[email protected]"
-YP989jsmskooo
profileName: "profile 3"
name: "Bill"
age: "102"
contactInfo: "[email protected]"
You could also separate the profiles into a separate node, which would flatten the data (a good thing) but it may not be necessary since it's a one to many relationship, user to their profiles.
When you observe the user node to load it, take the value stored in the defaultProfile child node and select it from the snapshot (dictionary) that was loaded in. That code is just a basic observing (reading) of a node.
My answer to
is almost the exact same code pattern (Swift) if you need some examples.
Upvotes: 1