[DDC-1276] Merging persistent collections broken if managed and merged collection are the same object Created: 13/Jul/11  Updated: 26/Jul/11  Resolved: 26/Jul/11

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.1
Fix Version/s: 2.0.7, 2.1.1
Security Level: All

Type: Bug Priority: Major
Reporter: Lienhart Woitok Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None
Environment:

FLOW3



 Description   

When FLOW3 maps request arguments to entities, it works on clones of the changed entities while entities, which are not affected by the request arguments stay the original objects. If the entity has a persistent collection which is not changed and therefore not cloned, the call to $repository->update() (which internally calls $em->merge()) eventually clears the $managedCol in $uow->doMerge() (line 1460 in current master), but if the $mergeCol is the same object, this is obviously wrong behavior as no related entities exist anymore in the entity to merge.

Made up example code (not sure if this simple example works as I have no test setup I could use for it)

/**
 * @entity
 * @scope prototype
 */
class A {}

/**
 * @entity
 * @scope prototype
 */
class B {
    /**
     * @var \Doctrine\Common\Collection\ArrayCollection<A>
     * @ManyToMany
     */
    public $relation;
}

$b = $repository->find(); // assume $b has some A in relation
$anotherB = clone $b;
$em->merge($anotherB);

After this relation of $b is empty



 Comments   
Comment by Benjamin Eberlei [ 26/Jul/11 ]

Fixed

Generated at Wed Oct 01 06:24:58 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.