diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index f35c20eff..d0f5bc022 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -462,6 +462,7 @@ class UnitOfWork implements PropertyChangedListener // A PersistentCollection was de-referenced, so delete it. if ( ! in_array($orgValue, $this->collectionDeletions, true)) { $this->collectionDeletions[] = $orgValue; + $changeSet[$propName] = $orgValue; // Signal changeset, to-many assocs will be ignored. } } } else if ($isChangeTrackingNotify) { diff --git a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php index c2df6c467..4ac1a8d00 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php @@ -3,7 +3,8 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Tests\Models\CMS\CmsUser, - Doctrine\Tests\Models\CMS\CmsGroup; + Doctrine\Tests\Models\CMS\CmsGroup, + Doctrine\Common\Collections\ArrayCollection; require_once __DIR__ . '/../../TestInit.php'; @@ -308,4 +309,37 @@ class ManyToManyBasicAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCa $this->_em->createQuery("DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE SIZE(u.groups) = 10")->execute(); $this->_em->createQuery("UPDATE Doctrine\Tests\Models\CMS\CmsUser u SET u.status = 'inactive' WHERE SIZE(u.groups) = 10")->execute(); } + + /** + * @group DDC-978 + */ + public function testClearAndResetCollection() + { + $user = $this->addCmsUserGblancoWithGroups(2); + $group1 = new CmsGroup; + $group1->name = 'Developers_New1'; + $group2 = new CmsGroup; + $group2->name = 'Developers_New2'; + + $this->_em->persist($group1); + $this->_em->persist($group2); + $this->_em->flush(); + $this->_em->clear(); + + $user = $this->_em->find(get_class($user), $user->id); + + $coll = new ArrayCollection(array($group1, $group2)); + $user->groups = $coll; + $this->_em->flush(); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $user->groups, + "UnitOfWork should have replaced ArrayCollection with PersistentCollection."); + $this->_em->flush(); + + $this->_em->clear(); + + $user = $this->_em->find(get_class($user), $user->id); + $this->assertEquals(2, count($user->groups)); + $this->assertEquals('Developers_New1', $user->groups[0]->name); + $this->assertEquals('Developers_New2', $user->groups[1]->name); + } }