DDC-834 - Commit fix for requesting references of classes that have subclasses. This is not possible, so we do an eager find instead. Yes this means there is yet another negative performance impact when using Inheritance STI and CTI.
This commit is contained in:
parent
b4aabf0ba6
commit
07016f6da5
@ -352,11 +352,15 @@ class EntityManager
|
||||
if ($entity = $this->unitOfWork->tryGetById($identifier, $class->rootEntityName)) {
|
||||
return $entity;
|
||||
}
|
||||
if ( ! is_array($identifier)) {
|
||||
$identifier = array($class->identifier[0] => $identifier);
|
||||
if ($class->subClasses) {
|
||||
$entity = $this->find($entityName, $identifier);
|
||||
} else {
|
||||
if ( ! is_array($identifier)) {
|
||||
$identifier = array($class->identifier[0] => $identifier);
|
||||
}
|
||||
$entity = $this->proxyFactory->getProxy($class->name, $identifier);
|
||||
$this->unitOfWork->registerManaged($entity, $identifier, array());
|
||||
}
|
||||
$entity = $this->proxyFactory->getProxy($class->name, $identifier);
|
||||
$this->unitOfWork->registerManaged($entity, $identifier, array());
|
||||
|
||||
return $entity;
|
||||
}
|
||||
|
@ -385,4 +385,29 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
|
||||
$this->assertEquals($manager->getId(), $pmanager->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-834
|
||||
*/
|
||||
public function testGetReferenceEntityWithSubclasses()
|
||||
{
|
||||
$manager = new CompanyManager();
|
||||
$manager->setName('gblanco');
|
||||
$manager->setSalary(1234);
|
||||
$manager->setTitle('Awesome!');
|
||||
$manager->setDepartment('IT');
|
||||
|
||||
$this->_em->persist($manager);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$ref = $this->_em->getReference('Doctrine\Tests\Models\Company\CompanyPerson', $manager->getId());
|
||||
$this->assertNotType('Doctrine\ORM\Proxy\Proxy', $ref, "Cannot Request a proxy from a class that has subclasses.");
|
||||
$this->assertType('Doctrine\Tests\Models\Company\CompanyPerson', $ref);
|
||||
$this->assertType('Doctrine\Tests\Models\Company\CompanyEmployee', $ref, "Direct fetch of the reference has to load the child class Emplyoee directly.");
|
||||
$this->_em->clear();
|
||||
|
||||
$ref = $this->_em->getReference('Doctrine\Tests\Models\Company\CompanyManager', $manager->getId());
|
||||
$this->assertType('Doctrine\ORM\Proxy\Proxy', $ref, "A proxy can be generated only if no subclasses exists for the requested reference.");
|
||||
}
|
||||
}
|
||||
|
@ -332,4 +332,21 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$contracts = $repos->findBy(array('salesPerson' => $this->salesPerson->getId()));
|
||||
$this->assertEquals(1, count($contracts), "There should be 1 entities related to " . $this->salesPerson->getId() . " for 'Doctrine\Tests\Models\Company\CompanyFlexUltraContract'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-834
|
||||
*/
|
||||
public function testGetReferenceEntityWithSubclasses()
|
||||
{
|
||||
$this->loadFullFixture();
|
||||
|
||||
$ref = $this->_em->getReference('Doctrine\Tests\Models\Company\CompanyContract', $this->fix->getId());
|
||||
$this->assertNotType('Doctrine\ORM\Proxy\Proxy', $ref, "Cannot Request a proxy from a class that has subclasses.");
|
||||
$this->assertType('Doctrine\Tests\Models\Company\CompanyContract', $ref);
|
||||
$this->assertType('Doctrine\Tests\Models\Company\CompanyFixContract', $ref, "Direct fetch of the reference has to load the child class Emplyoee directly.");
|
||||
$this->_em->clear();
|
||||
|
||||
$ref = $this->_em->getReference('Doctrine\Tests\Models\Company\CompanyFixContract', $this->fix->getId());
|
||||
$this->assertType('Doctrine\ORM\Proxy\Proxy', $ref, "A proxy can be generated only if no subclasses exists for the requested reference.");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user