Open steevanb opened 7 years ago
Cross-referencing doctrine/mongodb-odm#1248, where we solved the same issue by unscheduling orphan removal in PersistentCollection::add
Looks good, but why this is not fixed for every databases ? Like MySQL ?
@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.
Ok thanks !
@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 https://github.com/doctrine/doctrine2/tree/971c40002522cfebe58d80aff21eef9fe439fa60/tests/Doctrine/Tests/ORM/Functional
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 ?