DDC-1189 - Bugfix with PersistentCollection#clear() in combination with lazy loading
This commit is contained in:
parent
7810f5fe69
commit
82f0c244e8
@ -572,6 +572,7 @@ final class PersistentCollection implements Collection
|
||||
}
|
||||
}
|
||||
$this->coll->clear();
|
||||
$this->initialized = true; // direct call, {@link initialize()} is too expensive
|
||||
if ($this->association['isOwningSide']) {
|
||||
$this->changed();
|
||||
$this->em->getUnitOfWork()->scheduleCollectionDeletion($this);
|
||||
|
@ -827,36 +827,6 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertEquals(0, $this->_em->getConnection()->fetchColumn("select count(*) from cms_addresses where id=".$addressId.""));
|
||||
}
|
||||
|
||||
public function testClearingCollectionDoesNotInitialize()
|
||||
{
|
||||
$user = new CmsUser();
|
||||
$user->username = "beberlei";
|
||||
$user->name = "Benjamin E.";
|
||||
$user->status = 'active';
|
||||
|
||||
$grp = new CmsGroup();
|
||||
$grp->setName("The Dudes");
|
||||
|
||||
$grp->addUser($user);
|
||||
$user->addGroup($grp);
|
||||
|
||||
$this->_em->persist($user);
|
||||
$this->_em->persist($grp);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$this->assertEquals(1, $this->_em->getConnection()->fetchColumn("select count(*) from cms_users_groups"));
|
||||
|
||||
$user2 = $this->_em->find(get_class($user), $user->id);
|
||||
$this->assertFalse($user2->groups->isInitialized());
|
||||
$user2->groups->clear();
|
||||
$this->assertFalse($user2->groups->isInitialized());
|
||||
$this->_em->flush();
|
||||
$this->assertFalse($user2->groups->isInitialized());
|
||||
|
||||
$this->assertEquals(0, $this->_em->getConnection()->fetchColumn("select count(*) from cms_users_groups"));
|
||||
}
|
||||
|
||||
public function testGetPartialReferenceToUpdateObjectWithoutLoadingIt()
|
||||
{
|
||||
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
|
||||
|
@ -357,4 +357,24 @@ class ManyToManyBasicAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCa
|
||||
$this->_em->getUnitOfWork()->initializeObject($user->groups);
|
||||
$this->assertTrue($user->groups->isInitialized(), "Collection should be initialized after calling UnitOfWork::initializeObject()");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1189
|
||||
* @group DDC-956
|
||||
*/
|
||||
public function testClearBeforeLazyLoad()
|
||||
{
|
||||
$user = $this->addCmsUserGblancoWithGroups(4);
|
||||
|
||||
$this->_em->clear();
|
||||
|
||||
$user = $this->_em->find(get_class($user), $user->id);
|
||||
$user->groups->clear();
|
||||
$this->assertEquals(0, count($user->groups));
|
||||
|
||||
$this->_em->flush();
|
||||
|
||||
$user = $this->_em->find(get_class($user), $user->id);
|
||||
$this->assertEquals(0, count($user->groups));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user