1
0
mirror of synced 2024-12-13 22:56:04 +03:00

Merge branch 'DDC-1041'

This commit is contained in:
Benjamin Eberlei 2011-03-03 23:11:24 +01:00
commit 1d5fef4144
3 changed files with 39 additions and 2 deletions

View File

@ -355,7 +355,7 @@ class EntityManager implements ObjectManager
// Check identity map first, if its already in there just return it. // Check identity map first, if its already in there just return it.
if ($entity = $this->unitOfWork->tryGetById($identifier, $class->rootEntityName)) { if ($entity = $this->unitOfWork->tryGetById($identifier, $class->rootEntityName)) {
return $entity; return ($entity instanceof $class->name) ? $entity : null;
} }
if ($class->subClasses) { if ($class->subClasses) {
$entity = $this->find($entityName, $identifier); $entity = $this->find($entityName, $identifier);
@ -395,7 +395,7 @@ class EntityManager implements ObjectManager
// Check identity map first, if its already in there just return it. // Check identity map first, if its already in there just return it.
if ($entity = $this->unitOfWork->tryGetById($identifier, $class->rootEntityName)) { if ($entity = $this->unitOfWork->tryGetById($identifier, $class->rootEntityName)) {
return $entity; return ($entity instanceof $class->name) ? $entity : null;
} }
if ( ! is_array($identifier)) { if ( ! is_array($identifier)) {
$identifier = array($class->identifier[0] => $identifier); $identifier = array($class->identifier[0] => $identifier);

View File

@ -98,6 +98,10 @@ class EntityRepository implements ObjectRepository
{ {
// Check identity map first // Check identity map first
if ($entity = $this->_em->getUnitOfWork()->tryGetById($id, $this->_class->rootEntityName)) { if ($entity = $this->_em->getUnitOfWork()->tryGetById($id, $this->_class->rootEntityName)) {
if (!($entity instanceof $this->_class->name)) {
return null;
}
if ($lockMode != LockMode::NONE) { if ($lockMode != LockMode::NONE) {
$this->_em->lock($entity, $lockMode, $lockVersion); $this->_em->lock($entity, $lockMode, $lockVersion);
} }

View File

@ -0,0 +1,33 @@
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Common\Collections\ArrayCollection;
require_once __DIR__ . '/../../../TestInit.php';
/**
* @group DDC-1041
*/
class DDC1041Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
public function setUp()
{
$this->useModelSet('company');
parent::setUp();
}
public function testGrabWrongSubtypeReturnsNull()
{
$fix = new \Doctrine\Tests\Models\Company\CompanyFixContract();
$fix->setFixPrice(2000);
$this->_em->persist($fix);
$this->_em->flush();
$id = $fix->getId();
$this->assertNull($this->_em->find('Doctrine\Tests\Models\Company\CompanyFlexContract', $id));
$this->assertNull($this->_em->getReference('Doctrine\Tests\Models\Company\CompanyFlexContract', $id));
$this->assertNull($this->_em->getPartialReference('Doctrine\Tests\Models\Company\CompanyFlexContract', $id));
}
}