[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



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;

After this relation of $b is empty

Comment by Benjamin Eberlei [ 26/Jul/11 ]


Generated at Sat Sep 05 03:56:14 EDT 2015 using JIRA 6.4.10#64025-sha1:5b8b74079161cd76a20ab66dda52747ee6701bd6.