Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding an existing object to a hasMany association doesn't persist after save() #47

Closed
mattaddy opened this issue Apr 17, 2014 · 3 comments

Comments

@mattaddy
Copy link

As an example, let's say we have a Book and a Chapter.

App.Book = DS.Model.extend({
  title: DS.attr('string'),
  chapters: DS.hasMany('chapter')
});

App.Chapter = DS.Model.extend({
  title: DS.attr('string')
});

Calling addObject() on a book.chapters array, providing an existing, non-dirty chapter instance doesn't persist after saving the book. For example,

store.find('book', 1).then(function(book) {
  store.find('chapter', 1).then(function(chapter) {
    book.get('chapters').addObject(chapter);
    book.save();
  });
});

The above code doesn't update the book.chapters object in Firebase.

However, when "dirtying" the chapter object, it persists fine. For example,

store.find('book', 1).then(function(book) {
  store.find('chapter', 1).then(function(chapter) {
    book.get('chapters').addObject(chapter);
    chapter.set('title', 'Updated Chapter Title');  // dirtying the chapter saves the object to book.chapters
    book.save();
  });
});

The above code updates the book.chapters object in Firebase.

@aputinski
Copy link
Collaborator

@mattaddy this has to do with #41. The problem I'm having right now is that there is no way for the adapter to know when a relationship has been modified. I'm working on a temporary fix where I will cache relationships after each save so that I can check for added/removed items.

@aputinski
Copy link
Collaborator

@mattaddy should be fixed in v1.0.5

@mattaddy
Copy link
Author

@aputinski thanks for all your work 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants