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

          Alex created issue -
          Alex made changes -
          Field Original Value New Value
          Description <?

            // $entity->items is m2m association with (for example) 2 items in it

            /////////////////////
            // 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
          <?

            // $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
          Alex made changes -
          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
          {code}

            // $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

          {code}
          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?
          Benjamin Eberlei made changes -
          Attachment DDC2143Test.php [ 11513 ]
          Benjamin Eberlei made changes -
          Status Open [ 1 ] Awaiting Feedback [ 10000 ]
          Benjamin Eberlei made changes -
          Link This issue is duplicated by DDC-1987 [ DDC-1987 ]
          made changes -
          Status Awaiting Feedback [ 10000 ] In Progress [ 3 ]
          Hide
          Benjamin Eberlei added a comment -

          Closed, no feedback.

          Show
          Benjamin Eberlei added a comment - Closed, no feedback.
          Benjamin Eberlei made changes -
          Status In Progress [ 3 ] Resolved [ 5 ]
          Resolution Cannot Reproduce [ 5 ]

          This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

          • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-2143, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

            People

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

              Dates

              • Created:
                Updated:
                Resolved: