ember-resource
ember-resource copied to clipboard
Support inverse relationships
In nested hasOne
and hasMany
associations, it's useful to have the associated objects have pointers back to the origin object. This can't be done by overriding init
since the object won't have been fetched and thus the associated objects may not exist. It can't be done by overriding the association method and calling _super
because the association is defined first in this class, not a parent.
I suggest the following:
Owner = Ember.Resource.define({
foo: {
type: 'Foo',
nested: true,
inverse: 'owner'
},
bars: {
type: Ember.ResourceCollection,
itemType: 'Bar',
nested: true,
inverse: 'owner'
}
});
This would declare owner
properties on the associated Foo
s and Bar
s. For example
someOwner.getPath('foo.owner') === someOwner; // true