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:
parent
482ff2d009
commit
65bbdc30de
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user