mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
OrphanRemoval does not work with ArrayCollection and manual persist which is not mentioned in the docs #6993
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @olsavmic on GitHub (Jun 15, 2022).
Bug Report
Summary
I'd say this issue does not have a simple solution and it just requires documentation change.
Assume we have following entities:
Current behavior
Following code will create an entity even though the collection should be empty:
The issue is caused by combination of
orphanRemovalwith manually calling$entityManager->persist($entity)which is hard to fix (as ArrayCollection does not have access to entity manager) yet undocumented so unexpected.Following code will work as expected:
Expected behavior
The only possible solution that comes to my mind is to document this behavior in
orphanRemovalpart and recommend using it alongsidecascade=["persist"]