Skip to content

Support inverse relationships #36

@jamesarosen

Description

@jamesarosen

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions