I have simple app working with Band entities. I have created the form where the user can update existing record. It's handled by this controller:
App.BandEditController = Ember.Controller.extend({
startEditing: function() {
var band = this.get('model');
var transaction = band.get('store').transaction();
transaction.add(band); <-- THIS IS THE PROBLEM (IN 2ND RUN)
this.transaction = transaction;
},
stopEditing: function() {
// rollback the local transaction if it hasn't already been cleared
var transaction = this.transaction;
if (transaction) {
transaction.rollback();
this.transaction = undefined;
}
this.startEditing();
},
save: function() {
this.transaction.commit();
this.transaction = undefined;
this.stopEditing();
},
cancel: function() {
this.stopEditing();
}
});
It's hugely inspired by this: https://github.com/dgeb/ember_data_example/blob/master/app/assets/javascripts/controllers/contact_edit_controller.js
When I display the form and perform the editing once, everything's OK. However, I'd like to keep the form displayed and allow the user to edit it again. With my approach, immediately after sending the updated record to the server, when the startEditing
method tries to add the band to the transaction again, I get this error:
Uncaught Error: assertion failed: Once a record has changed, you cannot move it into a different transaction
I understand I cannot create another transaction with the same object. But why? And how can I fix this?
(Btw, is there any simplier approach for updating the records than those transactions, startEditing and stopEditing methods? It seems a bit overkill to me.)