Is it possible to revert the model to a clean state? I mean undo all the changes to its properties and mark the state as being clean?
Asked
Active
Viewed 2,339 times
3
-
Now that the PR has been merged, you should mark @Zeus' answer as the accepted one. – pangratz May 03 '12 at 07:56
4 Answers
7
Ember-Data now has an awesome implementation of this. They utilize the transaction class to manage the changes to your objects, which imo is the right place for this. To rollback changes on a model:
Obtain the Model
// if PostController is a ArrayController or ArrayProxy p = App.PostController.objectAt(0);
Get the object's associated transaction instance and call it's rollback() method.
p.get("transaction").rollback();

Zeus
- 161
- 1
- 3
2
From Ember 2.0 this is the way to go (once you have got your model object 'model'):
model.rollbackAttributes();
See https://guides.emberjs.com/v2.0.0/models/creating-updating-and-deleting-records/

froskos
- 494
- 5
- 10
1
There is an open PullRequest by Paul Chavard @tchak, see https://github.com/emberjs/data/pull/176

pangratz
- 15,875
- 7
- 50
- 75
0
UPDATE: works with ember version <= 1.13
this.get('model').rollback();
see similar question: Revert change to ember data model