ember-parse-adapter icon indicating copy to clipboard operation
ember-parse-adapter copied to clipboard

Parent models should be saved on model deletion

Open igorsantos07 opened this issue 9 years ago • 2 comments

When you remove a model that pertains to an Array of a related model, that array is updated by Ember Data but not stored unless you manually call the parent model save() method.

Currently I'm solving this issue with the following code, but I think this should be automatic?

Board = ParseModel.extend
  name:    DS.attr 'string'
  project: DS.belongsTo 'project', async: true, inverse: 'boards'

  didDelete: ->
    @get('project').then (proj)-> proj.save()

igorsantos07 avatar May 31 '15 01:05 igorsantos07

Actually, I've noticed (not sure but it seems it started happening only this night) the adapter is not removing correctly the related information.

Example:

A Post has 4 Comments. One of those Comments is removed by its author; we call comment.destroyRecord(). That call will also remove the comment from Post.comments. Now post.comments has only 3 models, but still wasn't persisted. We call post.save(). The adapter will send an addUnique operation with those 3 items, but this will not remove the 4th comment from the database, creating an inconsistency.

It seems there's no register of what items were removed anymore (hasMany._deletedItems).

igorsantos07 avatar Jun 01 '15 04:06 igorsantos07

The issue in the last comment may be solvable by #49?

The problem in the main body is still unrelated to failing on removing data, I think.

igorsantos07 avatar Jun 01 '15 05:06 igorsantos07