1
0
mirror of synced 2025-01-18 22:41:43 +03:00

DDC-978 - Fix bug where Collection gets cleared (again) when calling flush multiple times and replacing a PersistentCollection with a new one.

This commit is contained in:
Benjamin Eberlei 2011-01-23 15:40:16 +01:00
parent 482ff2d009
commit 65bbdc30de
2 changed files with 36 additions and 1 deletions

View File

@ -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) {

View File

@ -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);
}
}