You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After removing a parent document with embedded documents and then changing this removal to an update in an onFlush listener, the embedded document updates are not applied.
Current behavior
After all operations have completed the embedded documents are not updated in the database, although the parent document is.
// Save the parent document with 1 embedded document, both initialized// with a `removedCount` of 0.$document = newTestDocument([newTestEmbeddedDocument()]);
$dm->persist($document);
$dm->flush();
// Sometime later, not necessarily in the same script that initially saves// the document, remove the document and trigger the event listener.$dm->remove($document);
$dm->flush();
The event listener that changes the removal operation to an update operation
class MyEventListener
{
publicfunctiononFlush(OnFlushEventArgs$eventArgs): void
{
$dm = $eventArgs->getDocumentManager();
$uow = $dm->getUnitOfWork();
foreach ($uow->getScheduledDocumentDeletions() as$document) {
if ($documentinstanceof TestDocument) {
// Increment the `removedCount` on both the parent document and// the embedded document$document->incrementRemovedCount();
// Re-persist the same document & recompute changeset to change the operation from a// removal to an update.$dm->persist($document);
$uow->recomputeSingleDocumentChangeSet($dm->getClassMetadata(TestDocument::class), $document);
}
}
}
}
Expected behavior
After all operations have completed, both the embedded documents as well as the parent document should be updated in the database to have a removedCount of 1. This was the case before the 2.11.x release. What actually happens is that the parent document will have a removedCount of 1 but the embedded document will have a removedCount of 0.
The text was updated successfully, but these errors were encountered:
jfortunato
added a commit
to jfortunato/mongodb-odm
that referenced
this issue
May 15, 2025
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.
Fixesdoctrine#2767
jfortunato
added a commit
to jfortunato/mongodb-odm
that referenced
this issue
May 15, 2025
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.
Fixesdoctrine#2767
Bug Report
Summary
After removing a parent document with embedded documents and then changing this removal to an update in an
onFlush
listener, the embedded document updates are not applied.Current behavior
After all operations have completed the embedded documents are not updated in the database, although the parent document is.
How to reproduce
Populate and remove the documents
The event listener that changes the removal operation to an update operation
Expected behavior
After all operations have completed, both the embedded documents as well as the parent document should be updated in the database to have a
removedCount
of 1. This was the case before the 2.11.x release. What actually happens is that the parent document will have aremovedCount
of 1 but the embedded document will have aremovedCount
of 0.The text was updated successfully, but these errors were encountered: