getoutreach / epf

A framework for keeping your Ember.js apps in sync.
http://epf.io
MIT License
369 stars 33 forks source link

deleteModel removes object from parent relationship when remove fail #119

Closed kdiogenes closed 10 years ago

kdiogenes commented 10 years ago

Let's supose that you have the classic Post <-> Comments relationship like this:

App.Post = Ep.Model.extend({
  title: Ep.attr('string'),
  body: Ep.attr('string'),

  comments: Ep.hasMany(App.Comment),
  user: Ep.belongsTo(App.User)
});

If you have the a list tha show the comments for a post and in each one you have a delete button that calls the following action:

deleteComment: (comment) ->
    @session.deleteModel(aStatus)
    @session.flush().then(null, ->
        alert('Failed')
    )

When flush fail, the alert is fired and the comment is removed from the list, needing a page reload to make it visible again.

ghempton commented 10 years ago

This is the expected behavior. The model is still deleted on the client and whatever error that happened needs to be resolved and flush() be called again. If your application wants to handle the error differently and instead revert the deletion, it can manually set the isDeleted property on the model back to true.

If you want cleaner isolation for changes like this, I would look into child sessions.