I am trying to manage ember-data transactions (creating and committing records) on a model that has two belongsTo relationships. In initially I was simply adding the new record to the transactions using (in Coffeescript):
@transaction.createRecord(App.Book, {author: App.router.authorController.get('content')})
This sets the author attribute (which is a DS.belongsTo relationship) to current author and then in a form the user sets the other attributes for the book, including another belongsTo relationship from a select element (let's say the publisher). This works fine, but if the user goes to create a second new record I get the following assertion raised:
Ember.assert("All records in a changed relationship must be in the same transaction. You tried to change the relationship between records when one is in " + t + " and the other is in " + prev, t === prev);
This is from line 203 of the one_to_many_change.js file in Ember Data
I take this to mean that I must manually add all the relevant model objects into the transaction. So I could add the author model to the transaction using something like:
author = App.router.authorController.get('content')
@transaction.add(author)
And then do the same for any publisher models that might be affected involved in the transaction (I was doing these operations within the console). However, when I do this I then get the following error:
Error: assertion failed: Once a record has changed, you cannot move it into a different transaction
This occurs even though the previous (original) transaction had been committed. Just wondering how others are dealing with this issues. I imagine assigning this kinds of relationships within transactions must be common process in Ember Data apps.