DDC-1276: Merging persistent collections broken if managed and merged collection are the same object #1605

Closed
opened 2026-01-22 13:19:40 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Jul 13, 2011).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user liwo:

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

Originally created by @doctrinebot on GitHub (Jul 13, 2011). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user liwo: 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
admin added the Bug label 2026-01-22 13:19:40 +01:00
admin closed this issue 2026-01-22 13:19:42 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jul 26, 2011):

Comment created by @beberlei:

Fixed

@doctrinebot commented on GitHub (Jul 26, 2011): Comment created by @beberlei: Fixed
Author
Owner

@doctrinebot commented on GitHub (Jul 26, 2011):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Jul 26, 2011): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1605