Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2143

$em->refresh($entity) doesn't refresh associations cleared with clear()

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Cannot Reproduce
    • Affects Version/s: 2.3
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      PHP 5.3 + APC, CentOS

      Description

      
        // $entity->items is m2m association
      
        /////////////////////
        // 1. Bug
      
        echo $entity->items->count(); // 2
      
        $entity->items->clear();
      
        echo $entity->items->count(); // 0
      
        $em->refresh($entity);
      
        echo $entity->items->count(); // 0 <-- ???
      
        //////////////////
        // 2. Workaround
      
        echo $entity->items->count(); // 2
      
        // remove items one by one
      
        $items = $entity->items->toArray();
        foreach ( $items as $item )
        {
          $entity->items->removeElement($item);
        }
      
        echo $entity->items->count(); // 0
      
        $em->refresh($entity);
      
        echo $entity->items->count(); // 2, as expected
      
      

        Issue Links

          Activity

          Hide
          Marco Pivetta added a comment - - edited

          This is because `clear` on an un-initialized collection doesn't initialize it. Can you confirm this by adding a call to

          $this->initialize()

          in the `clear` method of `Doctrine\ORM\PersistentCollection`?

          Show
          Marco Pivetta added a comment - - edited This is because `clear` on an un-initialized collection doesn't initialize it. Can you confirm this by adding a call to $ this ->initialize() in the `clear` method of `Doctrine\ORM\PersistentCollection`?
          Hide
          Marco Pivetta added a comment -

          Related to DDC-1987

          Show
          Marco Pivetta added a comment - Related to DDC-1987
          Hide
          Marco Pivetta added a comment -

          Alex ping?

          Show
          Marco Pivetta added a comment - Alex ping?
          Hide
          Benjamin Eberlei added a comment -

          I cannot reproduce this issue, see the testscript attached (put into tests/Doctrine/Tests/ORM/Functional/Ticket/). Can you try to make this code fail?

          Show
          Benjamin Eberlei added a comment - I cannot reproduce this issue, see the testscript attached (put into tests/Doctrine/Tests/ORM/Functional/Ticket/). Can you try to make this code fail?
          Hide
          Benjamin Eberlei added a comment -

          Closed, no feedback.

          Show
          Benjamin Eberlei added a comment - Closed, no feedback.

            People

            • Assignee:
              Benjamin Eberlei
              Reporter:
              Alex
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: