1
0
mirror of synced 2025-01-31 04:21:44 +03:00

Use find() if the indexBy field is the identifier

This commit is contained in:
Sander Marechal 2013-06-20 13:45:38 +02:00
parent 53c9ffda30
commit 3b92cfac5a
2 changed files with 12 additions and 0 deletions

View File

@ -521,6 +521,12 @@ final class PersistentCollection implements Collection, Selectable
&& $this->association['fetch'] === Mapping\ClassMetadataInfo::FETCH_EXTRA_LAZY
&& isset($this->association['indexBy'])
) {
$class = $this->em->getClassMetadata($this->association['targetEntity']);
if (!$class->isIdentifierComposite && $class->isIdentifier($this->association['indexBy'])) {
return $this->em->find($class->name, $key);
}
return $this->em->getUnitOfWork()->getCollectionPersister($this->association)->get($this, $key);
}

View File

@ -532,6 +532,9 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertFalse($user->articles->isInitialized());
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount());
$this->assertSame($article, $this->_em->find('Doctrine\Tests\Models\CMS\CmsArticle', $this->articleId));
$article = $user->articles->get($this->articleId);
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Getting the same entity should not cause an extra query to be executed");
}
/**
@ -549,6 +552,9 @@ class ExtraLazyCollectionTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertFalse($user->groups->isInitialized());
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount());
$this->assertSame($group, $this->_em->find('Doctrine\Tests\Models\CMS\CmsGroup', $this->groupId));
$group = $user->groups->get($this->groupId);
$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount(), "Getting the same entity should not cause an extra query to be executed");
}
/**