Reputation: 4395
What is the recommended way of discarding changes made to records?
I have the following logic to revert dirty records to their original state.
if controller.get('isDirty')
controller.get('content').rollback()
This works unless an unsuccessful attempt has been made to commit the record.
If I try to commit the changes and the server responds with errors, it's no longer possible to rollback the record this way. In this case, does Ember Data or the RESTAdapter provide a built-in method of reverting the record to its original state?
I'm using the packaged DS.RESTAdapter
with Ember Data revision 11
Upvotes: 4
Views: 2711
Reputation: 7674
I've found something that apparently works although I don't know why. Here is what I do in my model:
App.User = DS.Model.extend({
becameInvalid: function(errors) {
this.get('transaction').rollback();
//this.rollback(); <- This doesn't work. You get becameClean error.
}
});
The comment from sly7-7 for that issue gave me the idea.
Upvotes: 2