Skip to content

Loading…

DDC-166: When entity is moved from one collection to another, it is still considered "orphaned" #2303

Closed
doctrinebot opened this Issue · 6 comments

2 participants

@doctrinebot

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.

@doctrinebot

Comment created by @beberlei:

Hm i think this should be marked as bug

@doctrinebot

Comment created by @beberlei:

Attached a patch to fix this issue, but its not really final yet.

Architectural questions:

  1. Are PersistentCollection::add() and PersistentCollection::remove() the only cases where unscheduleOrphanRemoval() is necessary? What about simple ArrayCollections on a new entity?
  2. What about TO_ONE associations with orphan removal?
@doctrinebot

Comment created by @beberlei:

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:

  1. Entity B unschedule Orphan Removal
  2. Entity A schedule Orphan Removal again (#fail)
@doctrinebot

Comment created by @beberlei:

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.

@doctrinebot

Issue was closed with resolution "Invalid"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.0.1 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.