1
0
mirror of synced 2025-01-29 19:41:45 +03:00

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:
Benjamin Eberlei 2010-10-11 20:11:23 +02:00
parent b4aabf0ba6
commit 07016f6da5
3 changed files with 50 additions and 4 deletions

View File

@ -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;
}

View File

@ -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.");
}
}

View File

@ -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.");
}
}