ember-resource icon indicating copy to clipboard operation
ember-resource copied to clipboard

Support inverse relationships

Open jamesarosen opened this issue 12 years ago • 0 comments

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 Foos and Bars. For example

someOwner.getPath('foo.owner') === someOwner; // true

jamesarosen avatar Mar 24 '12 23:03 jamesarosen