Reputation: 3429
We have an Ember.js application which uses Ember Data. We are trying to do the following:
We have found that this does not work
object.destroyRecord().then ->
# handle success
, (reason)->
object.rollback()
# prompt for the unlock
In both cases, we see an error that looks like:
Error: Assertion Failed: calling set on destroyed object
But it isn't clear how to remove the isDestroyed
state once it has been set.
In general, it seems that, in either case, once we call destroyRecord
, there is no way to rollback the changes to a pre-deleted state once, even if there is a server error.
Upvotes: 4
Views: 706
Reputation: 788
I've found that you need to put the rollback call in becameError() function.
// Overwrite default destroyRecord
destroyRecord: function () {
this.deleteRecord();
this.save().then(
function (){
//Success
},
function () {
//Failure
}
);
},
becameError: function (item) {
this.rollback();
}
The item will disappear from views until the server returns the error and then magically reappear.
Upvotes: 0
Reputation: 811
Try deleteRecord, followed by save. The docs explicitly state that this allows you to rollback on error.
object.deleteRecord()
object.save().then( ->
# handle success
, (reason) ->
object.rollback()
)
Upvotes: 1