Rolling back a model after failed delete doesn't update view


#1

I’m trying to catch and handle a failed delete request by rolling back the model and having it remain in the view, but I’m having problems. I’ve got the following in my controller’s delete action:

model.delete();

model.save().then(function() {

  alert('Deleted!);

}, function(err) {

  alert('Delete failed...');
  model.rollback();

});

This seems to work fine, I can see that the model quickly disappears from the store and then is instantly added back in, however the problem is that it just doesn’t reappear in the view.

Both before and after the delete/rollback the model has the following properties

isLoaded:true
isDirty: false
isSaving: false
isDeleted: false
isError: false
isNew: false
isValid: true

I’m on Ember 1.11.1 and Ember Data 1.0.0-beta.16.1

Is this expected behaviour, or am I missing something? Any info would be greatly appreciated!


#2

As I understand, models marked for deletion should not immediately leave datastore. Can you try the way, described at the EmberGuides?

store.find('post', 1).then(function (post) {
  post.deleteRecord();
  post.get('isDeleted'); // => true
  post.save(); // => DELETE to /posts/1
});

// OR
store.find('post', 2).then(function (post) {
  post.destroyRecord(); // => DELETE to /posts/2
});

Instead of delete, a call to deleteRecord() is issued.


#3

Ah apologies a deleteRecord() is what I’m doing, mistyped my original controller. I’ve tried doing a straight destroyRecord() too and the same thing happens there.

Just to reiterate, the delete action is working fine, if I allow the request to go through then the delete succeeds and everything works as expected, it’s just if I manually cause it to fail then roll it back, then the record re-appears in the datastore (as expected), but not in the view.


#4

Hi,
I’ve the same issue and can’t make the record reappear in the view.
Did you find a solution for this? If yes, could you please quickly describe what you did?
Thanks in advance!