Resetting an ember-data model

How do people deal with a model that has errored or is in the isError state.

I have hacked together a concoction like this:

I first of all trap the error: 'becameInvalid', (result) =>
  @send 'flashError', contact
  result.reset() 'becameError', (result) =>
  @send 'flashError', 'An error has occurred and the contact cannot be updated.'

I then have a reset method on the model like this:

App.Model = DS.Model.extend
  reset: ->
    state = if @get('id')


How do others handle this?

In the becameError or becameInvalid state, a commit will not work. The state must first be “reset” to uncommitted. In case of a new record, you can do this by using this.get('stateManager').transitionTo('loaded.created.uncommitted') - in case of an update use this.get('stateManager').transitionTo('loaded.updated.uncommitted'). Once in uncommitted state, you can try to commit again.

There is however one tricky problem: in case of the becameInvalid state, you will need to use the store defaultTransaction to do the subsequent commit. This results in some dirty checks in teh code; see my save code below:

save: function () {

//Commit - record goes in Flight state

//After a becameInvalid state, transaction.commit() does not work; use defaultTransaction in that case - very dirty check ...
if (this.get('') == "uncommitted") {

var author = this.get('model');'didCreate', this, function () {
  this.transitionToRoute('author.edit', author);

//If response is error (e.g. REST API not accessible): becameError fires'becameError', this, function () {

//If response is 422 (validation problem at server side): becameInvalid fires'becameInvalid', this, function () {
  this.set('errors', this.get('content.errors'));

Hope this helps. Most probably, this is an area that will be improved in teh final release of Ember data.


I am doing the exact same transition. I’m not sure I understand.