Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "reset" an ember-data model if it's currently dirty

I can't seem to find the updated api for ember-data that lets you reset a model.

Example, I'm inside my route during the willTransition action and I find the model is dirty. I ask the user if they want to save changes before leaving (ie- they hit the back button on a form by accident / on purpose). If they opt to transition anyway I'd like a way to "reset" the model.

An older api mentioned "removeDirtyFactors" but I'm using 1.0 beta 4+ and this doesn't seem to be around anymore.

FooRoute = Ember.Route.extend({
  actions: function() {
    willTransition: function(transition) {
      var dirty = this.get('controller.content.isDirty');
      if (dirty && !confirm("ask the user something")) {
        transition.abort();
      }else{
        return true;
      }
    }
  }
});
like image 658
Toran Billups Avatar asked Jan 10 '14 04:01

Toran Billups


1 Answers

You can use this method:

model.rollbackAttributes();

More details:

API Documentation

like image 198
Kingpin2k Avatar answered Oct 12 '22 05:10

Kingpin2k