When I call deleteRecord()
on some of my hasMany relations, Ember Data sends a (successful) DELETE
request, but the record is not removed from the
I found the solution. It seems like deleteRecord
calls clearRelationships
, which in turn sets the belongsTo
of the model to null
. However it does not clear the inverse (i.e. it does not remove the model from the hasMany
relation of the parent). The following code fixed it.
var model = this.get('model');
model.eachRelationship(function(name, relationship){
if (relationship.kind === "belongsTo") {
var inverse = relationship.parentType.inverseFor(name);
var parent = model.get(name);
if (inverse && parent) parent.get(inverse.name).removeObject(model);
}
});
this.get('model').deleteRecord();
this.get('model').save();
However in my opinion this should be handled by Ember (Data). It seems like it is (most of the time), since this worked fine in other parts of my code. So likely this situation is some sort of edge case. Any thoughts on what might be going on are much appreciated.