Lets say I have two kinds of objects users and accounts. Users can have many Accounts and share them with other Users. So AccountA might be available to User1 and User2. Whi
Before jumping into specifics, there are a few things you'll want to keep in mind:
With that in mind, I'd recommend storing the data like your first example, but without using arrays:
users: {
1: {
name: 'Ted',
accounts: {
1: true,
2: true
}
}
2: {
name: 'Frank',
accounts: {
1: true
}
}
}
accounts: {
1: {
name: "Checking"
},
2: {
name: "Savings"
}
}
This will let you easily get all of the accounts for a particular user. If you need to also be able to go the other direction (all of the users for an account), you'll have to duplicate that information and store it in the accounts as well. E.g.:
accounts: {
1: {
name: "Checking",
users: {
1: true,
2: true
}
},
2: {
name: "Savings",
users: {
1: true
}
}
}
Hope this helps!