Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to undo changes to a model?

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?

like image 773
Dziamid Avatar asked May 10 '26 08:05

Dziamid


1 Answers

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:

  1. Obtain the Model

    // if PostController is a ArrayController or ArrayProxy
    p = App.PostController.objectAt(0);
    
  2. Get the object's associated transaction instance and call it's rollback() method.

    p.get("transaction").rollback();
    
like image 157
Zeus Avatar answered May 12 '26 10:05

Zeus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!