Jira issue originally created by user ablock:
If I remove an entity from a PersistentCollection, the UnitOfWork marks is as "orphaned" (assuming I set that in my entity). If I then move the entity to another collection, this status doesn't get removed, and the UnitOfWork deletes it.
Comment created by @beberlei:
Hm i think this should be marked as bug
Attached a patch to fix this issue, but its not really final yet.
Patch that solves the issue with ArrayCollections that cannot unschedule orphan removals themselves.
Now only the problem with ONETO_ONE relation persists. However this means we might need a new UnitOfWork instance variable. The reason for this is that the Orphan removal of ONE_TOONE is detected in "UnitOfWork::computeChangeSets". We cannot use the current "UnitOfWork::unscheduleOrphanRemoval" for this, since it would fail on the following ordering problem:
We discussed this issue and came to the conclusion that this behavior is not a bug rather a documentation issue.
Enabling orphanRemoval=true is the semantical equivalent of saying that the orphan entity is privately owned by the parent. That means it should not be re-used!
If you want to re-use entities you should rather look into explicit $em->remove() calls or using cascade=remove.
I updated the documentation accordingly.
Issue was closed with resolution "Invalid"
Imported 2 attachments from Jira into https://gist.github.com/0462974f72618e031f98