mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
PersistentCollection::clear() and removeElement() with orphanRemoval #5579
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 @steevanb on GitHub (Jun 19, 2017).
Hi !
I have a simple User entity, linked to Comment by oneToMany, with orphanRemoval:
if i call that:
or that:
Finally, Comment entity will be deleted.
Why ? Cause in PersistentCollection::clear() and removeElement(), orphanRemoval will add your deleted entity in UnitOfWork::$orphanRemovals.
flush() will read UnitOfWork::$orphanRemovals, and delete all entities, although they are deleted then added
See https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/PersistentCollection.php#L395 and https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/PersistentCollection.php#L560
How can i delete then add same entity, with orphanRemoval ?
@alcaeus commented on GitHub (Jun 19, 2017):
Cross-referencing doctrine/mongodb-odm#1248, where we solved the same issue by unscheduling orphan removal in PersistentCollection::add
@steevanb commented on GitHub (Jun 19, 2017):
Looks good, but why this is not fixed for every databases ? Like MySQL ?
@alcaeus commented on GitHub (Jun 19, 2017):
@steevanb Because I only maintain ODM where I originally found the issue. I haven't used an SQL based database in years. I'll try to port the fix over to ORM.
@steevanb commented on GitHub (Jun 19, 2017):
Ok thanks !
@lcobucci commented on GitHub (Jun 23, 2017):
@steevanb could you please send us a PR with a functional test that reproduces this behaviour? Sending just an example doesn't give us the complete overview of things and why it fails. You can find examples on
971c400025/tests/Doctrine/Tests/ORM/Functional