You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
This caused unexpected behavior in my project where I successfully deleted a record and DS.ActiveModelAdapter dispatched a (successful) DELETE request to my
Rails backend - however the view still kept showing the deleted element. In the particular situation that has this issue am using the {{render}} helper to display a list of items. Other parts of my code (where I don't use {{render}}) work fine. Also see this related Stackoverflow Question.
The following code fixed the problem and allows for consistently successful deleting of child elements:
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.
The text was updated successfully, but these errors were encountered:
It seems like
deleteRecord()
callsclearRelationships()
, which in turn sets thebelongsTo
of the model tonull
. However it does not clear the inverse (i.e. it does not remove the model from thehasMany
relation of the parent).This caused unexpected behavior in my project where I successfully deleted a record and
DS.ActiveModelAdapter
dispatched a (successful)DELETE
request to myRails backend - however the view still kept showing the deleted element. In the particular situation that has this issue am using the
{{render}}
helper to display a list of items. Other parts of my code (where I don't use{{render}}
) work fine. Also see this related Stackoverflow Question.The following code fixed the problem and allows for consistently successful deleting of child elements:
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.
The text was updated successfully, but these errors were encountered: