I have a simple application which defines two classes, a Person
and a PersonGroup
, wherein there is a many-to-many relationship in place. A Person can have no group, or be assigned to all groups, and anything in between.
The example on backbonerelational.org suggests using an in-between model for many-to-many relationships, however I can't get this pattern to work with fetching (deserializing) and saving (serializing).
What I want to do is use Backbone to deserialize a JSON similar to the following:
{
People:
[
{
"ID": 1,
"Name": "John"
},
{
"ID": 2,
"Name": "Bob"
},
{
"ID": 3,
"Name": "Tim"
},
],
PeopleGroups:
[
{
"ID": 1,
"Name": "Owners",
"People":
[
1,
2
],
},
{
"ID": 2,
"Name": "Everyone",
"People":
[
1,
2,
3
],
},
]
}
I'm using Knockback/Knockout for data binding so the problem is I need to be able to access the relationships by reference. An array of IDs does not do me any good, unless I can create a Knockback.CollectionObservable to wrap the collection and resolve the IDs to references.