Use find() if the indexBy field is the identifier
This commit is contained in:
parent
53c9ffda30
commit
3b92cfac5a
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user