[DDC-2143] $em->refresh($entity) doesn't refresh associations cleared with clear() Created: 14/Nov/12  Updated: 01/May/13  Resolved: 01/May/13

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.3
Fix Version/s: None
Security Level: All

Type: Bug Priority: Critical
Reporter: Alex Assignee: Benjamin Eberlei
Resolution: Cannot Reproduce Votes: 0
Labels: None
Environment:

PHP 5.3 + APC, CentOS


Attachments: File DDC2143Test.php    
Issue Links:
Duplicate
is duplicated by DDC-1987 Cascading "refresh" does not work on ... Resolved

 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



 Comments   
Comment by Marco Pivetta [ 23/Jan/13 ]

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

Comment by Marco Pivetta [ 23/Jan/13 ]

Related to DDC-1987

Comment by Marco Pivetta [ 21/Feb/13 ]

Alex ping?

Comment by Benjamin Eberlei [ 31/Mar/13 ]

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?

Comment by Benjamin Eberlei [ 01/May/13 ]

Closed, no feedback.

Generated at Fri Apr 25 08:19:59 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.