[DDC-2143] $em->refresh($entity) doesn't refresh associations cleared with clear() Created: 14/Nov/12  Updated: 24/Jan/15  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

PHP 5.3 + APC, CentOS

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


  // $entity->items is m2m association

  // 1. Bug

  echo $entity->items->count(); // 2


  echo $entity->items->count(); // 0


  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 )

  echo $entity->items->count(); // 0


  echo $entity->items->count(); // 2, as expected

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


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.

Comment by Doctrine Bot [ 24/Jan/15 ]

A related Github Pull-Request [GH-1218] was labeled:

Generated at Tue Jul 28 17:56:20 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.