Skip to content

Instantly share code, notes, and snippets.

@tim-evans
Created April 29, 2011 17:34
Show Gist options
  • Save tim-evans/948667 to your computer and use it in GitHub Desktop.
Save tim-evans/948667 to your computer and use it in GitHub Desktop.
relationships.js
MyApp.Person = SC.Record.extend({
name: SC.Record.attr(String),
family: SC.Record.toOne(MyApp.Family,
inverse: 'people',
isMaster: YES
})
});
MyApp.Family = SC.Record.extend({
name: SC.Record.attr(String),
people: SC.Record.toMany(MyApp.Person,
inverse: 'family',
isMaster: NO
})
});
MyApp.DataSource = SC.DataSource.extend({
... snip snip snip ...
_didRecievePersonRecord: function (store, storeKey, person) {
var fStoreKey = store.storeKeyFor(MyApp.Family, person.family),
family = store.readDataHash(fStoreKey);
family.people = family.people || [];
family.people.push(person.guid);
store.pushRetrieve(MyApp.Family, null, family, fStoreKey);
store.dataSourceDidComplete(storeKey, person, person.guid);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment