Skip to content
This repository has been archived by the owner on Oct 15, 2021. It is now read-only.

A bug in clean-embedded-children #8

Open
sergetab opened this issue May 5, 2015 · 6 comments
Open

A bug in clean-embedded-children #8

sergetab opened this issue May 5, 2015 · 6 comments

Comments

@sergetab
Copy link

sergetab commented May 5, 2015

Found a bug in the clean-embedded-children.

After doing this

child.send('willCommit');
child.set('_attributes', {});
child.send('didCommit');

the child will become non-dirty, BUT all changed attributes will have old(original) value. So if, for example, you change a field again to it's previous value, it would not become dirty.

After some debugging, the right way to do it I think is

child.send('willCommit');
child._inFlightAttributes = child._attributes;
child._attributes = Ember.create(null);
child.send('didCommit');

That way after 'didCommit' all values from '_inFlightAttributes ' will be merged to '_data' automatically, so that values do update.

Also I think doing 'willCommit' and 'didCommit' for rollback is redundant.

@lolmaus
Copy link
Owner

lolmaus commented May 5, 2015

Can you please PR a failing test case?

@sergetab
Copy link
Author

sergetab commented May 6, 2015

Let me try to explain it in another way instead. It is quite simple really.

Attributes are stored in three places in Ember Data _data (saved data), _attributes (dirty attribute values), _inFlightAttributes (values that are being saved and about to be applied to _data).

In your code you just clear out _attributes like this

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

That way dirty values are lost. What is missing is

child._inFlightAttributes = child._attributes;

before that. If you assign _inFlightAttributes, didCommit will merge them back to _data.

@lolmaus
Copy link
Owner

lolmaus commented Jun 27, 2015

Thank you for your explanation. But could you provide a sequence of steps of working with a StainedByChildren-powered model that result in the issue? I need a failing test case.

@Mifrill
Copy link

Mifrill commented Nov 19, 2020

Hey guys @lolmaus , @sergetab , any updates here?

@lolmaus
Copy link
Owner

lolmaus commented Nov 19, 2020

@Mifrill Hey comrade, this addon is entirely unmaintained and is likely to be incompatible with modern versions of Ember Data since it was relying on private API.

@Mifrill
Copy link

Mifrill commented Nov 19, 2020

@lolmaus okay, thanks for the quick response, will deprecate this addon for our app then, thank you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants