2

I have two simple models in my Ember application that work like so:

App.Book = DS.Model.extend({
  tags: DS.hasMany('tag')
});

App.Tag = DS.Model.extend({
  books: DS.hasMany('book', { async: true })
});

Users can easily add and remove tags to a given book via our UI. The code that runs when a user removes a tag, for example, is:

book.get('tags').removeRecord(tagToRemove);
book.save();

This works just fine in removing the tag from the book. However, the tag model itself still references the book. In other words, the inverse relationship is not automatically updated.

EDIT:

After doing a JS Bin (http://jsbin.com/ucanam/1574/edit), it seems the reason the tag's books property is not updating automatically is because of the { async: true } option I passed. That said, I'm not sure I can really afford to remove that option, because a tag may have millions of books and I don't want to load all of them with the tag.

Any way to get things working as-is?

4

1 回答 1

0

Ember Data 从两者中“神奇地”删除的唯一方法是删除记录。如果您只是从其他记录之一中删除该记录,从技术上讲,Ember Data 并不是肯定的,您不希望仍然具有从其他记录到该记录的其他关系。

于 2013-10-21T21:39:59.793 回答