Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Revert change to ember data model

Is there a way to revert a change to an Ember Data model easily?

I have a model bound to an edit view. This view enables the user to cancel editing, at which point I'd like to revert the changes to the model. Is there an easy way to do this without cloning all the values off the side?

like image 230
outside2344 Avatar asked Jun 07 '12 16:06

outside2344


2 Answers

Starting from Ember Data version 2, there are not transactions anymore, but you can reset models to their last status before saved editions with:

model.rollbackAttributes();
like image 119
froskos Avatar answered Oct 13 '22 18:10

froskos


Ember Data supports the concept of transactions. We can create a transaction and assign Ember data records to them and if we want to undo the changes we can call the transactions rollback() method. Also if we do not create an explicit transaction the records are assigned to a default transaction which can be rolled back by calling the rollback() method on the DS.store object itself.

like image 41
Gaurav Shetty Avatar answered Oct 13 '22 20:10

Gaurav Shetty