One way relationships


#1

Is it valid to have one way relationships in ember data?

Any unintended consequences of doing something like this?

App.Foo = DS.Model.extend({
  bar: DS.belongsTo('App.Bar')
});

App.Bar = DS.Model.extend({
  // has no concept or dependency upon Foo model
});

My assumption is in my app I will always know the Foo and will only be concerned with the associated Bars. But will not need to find any Foos via a Bar.


#2

I can’t speak for the actual intended support ember-data has for this, but it has worked for me so far and the DS.RelationshipChange component has handlers for one-to-none and many-to-none relationship changes, so it looks like the support is indeed intentional.

The only complication I’ve run into while doing this is that if you defined another relationship on Bar back to Foo that is completely unrelated to the belongsTo relationship that Foo has with Bar, then ember-data will get confused and assume that the two relationships are related. There does not appear to be a way to explicitly define a *-to-none relationship.

More info here: https://github.com/emberjs/data/pull/1109