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}
          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 ]
          Benjamin Eberlei made changes -
          Status In Progress [ 3 ] Resolved [ 5 ]
          Resolution Cannot Reproduce [ 5 ]

            People

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

              Dates

              • Created:
                Updated:
                Resolved: