Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

One way relationship in Ember Data?

I need to figure out a way to do a one way relationship in Ember Data. Up until now, I've just put the relationship in only one model, and that's worked well. The problem is that model A becomes dirty when model B is deleted, even though model A has absolutely no concept of model B. How can I have model B point to model A, and make it so that A completely ignores the relationship? I don't mind declaring the relationship in class A to have the proper inverse, I just don't want models of type A to become dirty when that relationship changes.

Also, just FYI, I'm using a rather old version of Ember. I'm using Ember.js RC7 and the Ember Data build from August 26th. And before you ask, no, I am not upgrading.

like image 277
GJK Avatar asked Dec 08 '22 12:12

GJK


1 Answers

After searching for several hours, I finally found an answer in the source code of Ember Data. I found this little snippet:

DS.OneToManyChange = {};
DS.OneToNoneChange = {};
DS.ManyToNoneChange = {};
DS.OneToOneChange = {};
DS.ManyToManyChange = {};

I then did a bit more browsing and found that one-to-none and many-to-none relationships are defined by explicitly making the inverse null. So this little line did the trick:

owner: DS.belongsTo('A', { inverse: null })
like image 78
GJK Avatar answered Dec 11 '22 02:12

GJK