Skip to content

Fix updates to embedded documents after removal #2768

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

Open
wants to merge 4 commits into
base: 2.11.x
Choose a base branch
from

Conversation

jfortunato
Copy link

Q A
Type bug
BC Break no
Fixed issues #2767

Summary

After a parent document and its embeds are removed and then subsequently persisted, the embedded documents didn't get updated. This happened because the parent document goes through an upsert operation, but PersistenceBuilder->prepareUpsertData() did not handle embedded associations in the same way that
PersistenceBuilder->prepareUpdateData() does. This fixes that issue so that an upserted parent document handles embed-many's the same was as an updated parent document.

Fixes #2767

jfortunato and others added 3 commits May 15, 2025 15:52
After a parent document and its embeds are removed and then subsequently
persisted, the embedded documents didn't get updated. This happened
because the parent document goes through an upsert operation, but
`PersistenceBuilder->prepareUpsertData()` did not handle embedded
associations in the same way that
`PersistenceBuilder->prepareUpdateData()` does. This fixes that issue so
that an upserted parent document handles embed-many's the same was as an
updated parent document.

Fixes doctrine#2767
Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jfortunato for opening this PR with a perfect test case.

I added a prefix to the test classes to prevent name conflict, and refactored the change on PersistenceBuilder to not have nested if blocks.

Could you add a test that remove an embedded document? I'm no expert on this code, but from the comments I get the impression that the change should be made in CollectionPersister.

$update = $this->prepareUpsertData($embeddedDoc);
foreach ($update as $cmd => $values) {
foreach ($values as $name => $value) {
$updateData[$cmd][$mapping['name'] . '.' . $key . '.' . $name] = $value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This modifies the object at a given position. I'm not sure about the compatibility of deleting documents from the embedded collection.

@GromNaN
Copy link
Member

GromNaN commented May 21, 2025

Oups, the last commit broke AtomicSetTest::testAtomicUpsert. Looking at it.

@GromNaN GromNaN requested a review from alcaeus May 21, 2025 10:26
) {
$updateData['$set'][$mapping['name']] = $this->prepareAssociatedCollectionValue($new, true);
}
// @EmbedMany and @ReferenceMany are handled by CollectionPersister

// @ReferenceMany is handled by CollectionPersister
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment was referring to @ReferenceMany which is already handled previously. I wonder if it's really relevant.

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

Successfully merging this pull request may close these issues.

Embedded documents not updated after changing a remove operation to an update
2 participants