1
0
mirror of synced 2024-12-14 15:16:04 +03:00

Merge branch 'DDC-1462'

This commit is contained in:
Benjamin Eberlei 2011-10-31 21:34:31 +01:00
commit 54217bd4c6
2 changed files with 25 additions and 1 deletions

View File

@ -672,7 +672,10 @@ final class PersistentCollection implements Collection
*/ */
public function slice($offset, $length = null) public function slice($offset, $length = null)
{ {
if (!$this->initialized && $this->association['fetch'] == Mapping\ClassMetadataInfo::FETCH_EXTRA_LAZY) { if ( ! $this->initialized &&
! $this->isDirty &&
$this->association['fetch'] == Mapping\ClassMetadataInfo::FETCH_EXTRA_LAZY) {
return $this->em->getUnitOfWork() return $this->em->getUnitOfWork()
->getCollectionPersister($this->association) ->getCollectionPersister($this->association)
->slice($this, $offset, $length); ->slice($this, $offset, $length);

View File

@ -326,6 +326,27 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertEquals(4, count($user->groups)); $this->assertEquals(4, count($user->groups));
} }
/**
* @group DDC-1462
*/
public function testSliceOnDirtyCollection()
{
$user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $this->userId);
/* @var $user CmsUser */
$newGroup = new \Doctrine\Tests\Models\CMS\CmsGroup();
$newGroup->name = "Test4";
$user->addGroup($newGroup);
$this->_em->persist($newGroup);
$qc = $this->getCurrentQueryCount();
$groups = $user->groups->slice(0, 10);
$this->assertEquals(4, count($groups));
$this->assertEquals($qc + 1, $this->getCurrentQueryCount());
}
private function loadFixture() private function loadFixture()
{ {
$user1 = new \Doctrine\Tests\Models\CMS\CmsUser(); $user1 = new \Doctrine\Tests\Models\CMS\CmsUser();