1
0
mirror of synced 2025-01-23 08:41:41 +03:00

Added index by consideration when eagerly loading to-many associations.

This commit is contained in:
Guilherme Blanco 2014-04-17 03:53:21 +00:00
parent 13afde0140
commit 54898eca60
2 changed files with 12 additions and 5 deletions

View File

@ -1161,7 +1161,7 @@ class BasicEntityPersister implements EntityPersister
$isAssocToOneInverseSide = $assoc['type'] & ClassMetadata::TO_ONE && ! $assoc['isOwningSide'];
$isAssocFromOneEager = $assoc['type'] !== ClassMetadata::MANY_TO_MANY && $assoc['fetch'] === ClassMetadata::FETCH_EAGER;
if ( ! ($isAssocFromOneEager || $isAssocToOneInverseSide)) {
continue;
}
@ -1192,6 +1192,10 @@ class BasicEntityPersister implements EntityPersister
$association = $assoc;
$joinCondition = array();
if (isset($assoc['indexBy'])) {
$this->rsm->addIndexBy($assocAlias, $assoc['indexBy']);
}
if ( ! $assoc['isOwningSide']) {
$eagerEntity = $this->em->getClassMetadata($assoc['targetEntity']);
$association = $eagerEntity->getAssociationMapping($assoc['mappedBy']);

View File

@ -39,10 +39,12 @@ class DDC440Test extends \Doctrine\Tests\OrmFunctionalTestCase
$client->setName('Client1');
$phone = new DDC440Phone;
$phone->setId(1);
$phone->setNumber('418 111-1111');
$phone->setClient($client);
$phone2 = new DDC440Phone;
$phone->setId(2);
$phone2->setNumber('418 222-2222');
$phone2->setClient($client);
@ -56,8 +58,9 @@ class DDC440Test extends \Doctrine\Tests\OrmFunctionalTestCase
$uw = $this->_em->getUnitOfWork();
$client = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC440Client', $id);
$clientPhones = $client->getPhones();
$p1 = $clientPhones[0];
$p2 = $clientPhones[1];
$p1 = $clientPhones[1];
$p2 = $clientPhones[2];
// Test the first phone. The assertion actually failed because original entity data is not set properly.
// This was because it is also set as MainPhone and that one is created as a proxy, not the
@ -156,8 +159,8 @@ class DDC440Client
*/
protected $main_phone;
/**
* @OneToMany(targetEntity="DDC440Phone", mappedBy="client", cascade={"persist", "remove"}, fetch="EAGER")
* @orderBy({"number"="ASC"})
* @OneToMany(targetEntity="DDC440Phone", mappedBy="client", cascade={"persist", "remove"}, fetch="EAGER", indexBy="id")
* @OrderBy({"number"="ASC"})
*/
protected $phones;
/**