Assertion Failure when deleting record with hasMany relationship

I have the following category model:

export default DS.Model.extend({
    createdAt: DS.attr('date'),
    updatedAt: DS.attr('date'),
    title: DS.attr('string'),
    organization: DS.belongsTo('organization'),
    description: DS.attr('string'),
    users: DS.hasMany('user',{async:false})
});

When I try and remove a record that uses this model with the following action:

deleteCategory: function() {
  var self = this;
  var removedCategory = this.get('model');
  removedCategory.deleteRecord();
  removedCategory.save().then(function(result) {
    var org = removedCategory.get('organization');
    org.get('categories').removeObject(result);
    org.save().then(function() {
      self.transitionToRoute('organization', org);
    });
  });
}

I get the following error:

Error: Assertion Failed: calling set on destroyed object at new Error (native) at Error.Ember.Error (http://localhost:8001/vendor/ember/ember.js:844:19) at Object.Ember.assert (http://localhost:8001/vendor/ember/ember.js:73:11) at set (http://localhost:8001/vendor/ember/ember.js:2969:9) at Ember.Object.extend.hasManyDidChange (http://localhost:8001/vendor/ember-data/ember-data.js:5951:11) at null. (http://localhost:8001/vendor/ember-data/ember-data.js:5940:18) at http://localhost:8001/vendor/ember/ember.js:3368:16 at Object.OrderedSet.forEach (http://localhost:8001/vendor/ember/ember.js:3211:10) at Object.Map.forEach (http://localhost:8001/vendor/ember/ember.js:3366:10) at Ember.Object.extend.reloadHasManys (http://localhost:8001/vendor/ember-data/ember-data.js:5937:23) ember.js:3461 Uncaught Error: Assertion Failed: Error: Assertion Failed: calling set on destroyed object

If I remove the users relationship from the model, the action works perfectly every time, but with it in I always am getting the error. Anyone able to point me in the right direction here?

Did you ever figure this one out? I’m trying to get my first hello world app up and Im stuck on the same thing.

Thanks!

Sorry, no I have never gotten this figured out. I left it alone for now, and will come back to it soon.

Do you think it might be because you are calling removedCategory.get('organization') after you already called deleteRecord on removedCategory?

I think I actually figured it out. My custom data adapter’s delete function was returning a json object. As soon I set it to return an empty string the issue went away.

I moved everything around and it didn’t solve it.

This resolved it for me as well. When I modified my api endpoint to return nothing rather than a json object it worked without error. That will get me by now, but it seems like something deeper is wrong here.

Hey, Thanks for posting this, it solved the problem for me as well ( using the Parse.com JS API ).

Thanks again, Matt

I am experiencing the same issue. I am relatively new to Ember, I am using the ember-indexeddb-adapter and am unsure of where to make the return change in the deleteRecord. My addition in the adapter right now allows the item to be deleted, but the error still occurs.

Would someone be willing to teach/show a newbie how to go making a change to prevent the assertion failure? I created an issue in the Github repo but would like to give more information on a fix for the issue.

Thank you!!

It somehow never occurred to me that the problem could be in the back-end rather than in the front-end…

For those struggling with what to do: You need to modify the response that the server is giving you when a DELETE is processed for the specific resource. How to do this highly depends on what technology you are using on the server-end. It could virtually be anything.

In my case I use NodeJS and Express so I would basically change one line from:

res.json(200, {my_model: removed_document}); to res.json(200, {});

Anyone knows how I can setup my custom data adapter in order to return an empty string instead of a JSON object?