Skip to content

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
}
// @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

2 participants