Search code examples
ember.jsember-data

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;
      }
    }
  }
});

Solution

  • You can use this method:

    model.rollbackAttributes();
    

    More details:

    API Documentation