-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Children are duplicated in parent's collection when using generated node names #379
Comments
can you turn this into a failing test case? |
First commit contains the functional tests; second commit contains the fix. I broke them up so you could more easily observe the failures against the current code. Note the use of strcmp in the fixed code, since array keys can be either integers or strings we need a type-safe comparison between the two. Comments welcome -- I think I understand things but I am pretty new to the code. This did fix the issue I was having, and all of the existing tests pass so I hope there is no regression introduced. |
can you open a PR with your changes? makes reviewing easier |
Done, although it seems to have created a new issue, so clearly I am not doing it correctly. : ) |
that is the normal behavior .. so all is well :) |
Resolve duplication issue when adding children to a parent's collection #379
fixed in #390 right? please reopen if i am mistaken and there is something left. |
When adding children that use auto-generated node names to a parent's children collection, each child is duplicated upon calling
DocumentManager::flush()
.Consider two documents, the first of which has only a collection of children:
And the second of which just stores some content:
Now, we can create a parent and add some children:
The result is not quite what we would expect!
Before the
DocumentManager::flush()
operation, the ArrayCollection contains the three new Documents with non-specific indices. After the operation, the new node names are used as the indices, but the originals are not removed from the collection, resulting in a duplicate of each.The offending code is in
UnitOfWork::computeChangeSet()
lines 1240-1247 as such:It appears that the result of this block is that
$actualData[$fieldName]
will always end up with duplicated data if the node name changes as part ofUnitOfWork::getChildNodename()
, which is guaranteed if the child is new and uses a generated name.It seems this could be fixed with a line of code to remove the old index upon insertion of the new one, but I am less familiar with the code as a whole so it's possible I am missing something or that this is intended (although it seems unlikely).
In the above sample code, if the
$exampleParent->getDetails()->add($exampleChild);
line is omitted, the children collection is never populated at all. This seems as though it may also be a bug, or perhaps just not yet implemented.If these are in fact bugs I am happy to fix them and submit a pull request, I just don't want to do so without a better understanding of the intent.
The text was updated successfully, but these errors were encountered: