Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1276

Merging persistent collections broken if managed and merged collection are the same object

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1
    • Fix Version/s: 2.0.7, 2.1.1
    • Component/s: ORM
    • Security Level: All
    • 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

        Activity

        Lienhart Woitok created issue -
        Benjamin Eberlei made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.0.7 [ 10150 ]
        Fix Version/s 2.1.1 [ 10153 ]
        Resolution Fixed [ 1 ]
        Benjamin Eberlei made changes -
        Workflow jira [ 12824 ] jira-feedback [ 14951 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback [ 14951 ] jira-feedback2 [ 16815 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 16815 ] jira-feedback3 [ 19068 ]

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Lienhart Woitok
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: