lolmaus / ember-cli-stained-by-children

Ember CLI addon: a mixin that makes the `isDirty` property of a record respect the dirtiness of its belongsTo/hasMany children
MIT License
25 stars 6 forks source link

clean-embedded-children not marking children clean in 1.0.0-beta.19.2 #11

Open melindaweathers opened 9 years ago

melindaweathers commented 9 years ago

When using the clean-embedded-children mixing with Ember-data beta 19.2, the children are no longer being marked as cleaned after they are saved. I'm not familiar with how this worked in the past, but at this version in ember-data, there is the following line checking the _attributes to determine whether the object isDirty: https://github.com/emberjs/data/blob/23a5b13a9bccd3f26515f4992dd59960d6649df0/packages/ember-data/lib/system/model/states.js#L548

This line is specifically checking the _attributes of the "internalModel" of the record, which apparently is not (immediately?) affected when we empty the _attributes of the child object.

I implemented the following hack to get things working again for me, changing line 40 of clean-embedded-children from:

child.set('_attributes', {});

to

child.set('_internalModel._attributes', {});

This works for my use case, but I'm not familiar enough with ember-data internals to know what the "right" way to do this actually would be.

(P.S. Thank you for writing this add-on. It has been extremely helpful!)

lolmaus commented 9 years ago

Fantastic! I'm gonna try it and merge tomorrow. Thank you for your effort.