1
0
mirror of synced 2025-02-02 21:41:45 +03:00

Merge pull request #1405 from taueres/master

EntityManager#getReference throw ORMException for unrecognized id
This commit is contained in:
Marco Pivetta 2015-11-06 23:07:21 -05:00
commit e7685c89da
3 changed files with 12 additions and 5 deletions

View File

@ -482,6 +482,11 @@ use Doctrine\Common\Util\ClassUtils;
} }
$sortedId[$identifier] = $id[$identifier]; $sortedId[$identifier] = $id[$identifier];
unset($id[$identifier]);
}
if ($id) {
throw ORMException::unrecognizedIdentifierFields($class->name, array_keys($id));
} }
// Check identity map first, if its already in there just return it. // Check identity map first, if its already in there just return it.
@ -493,10 +498,6 @@ use Doctrine\Common\Util\ClassUtils;
return $this->find($entityName, $sortedId); return $this->find($entityName, $sortedId);
} }
if ( ! is_array($sortedId)) {
$sortedId = array($class->identifier[0] => $sortedId);
}
$entity = $this->proxyFactory->getProxy($class->name, $sortedId); $entity = $this->proxyFactory->getProxy($class->name, $sortedId);
$this->unitOfWork->registerManaged($entity, $sortedId, array()); $this->unitOfWork->registerManaged($entity, $sortedId, array());

View File

@ -296,7 +296,7 @@ class ORMException extends Exception
/** /**
* @param string $className * @param string $className
* @param string $fieldName * @param string[] $fieldNames
* *
* @return ORMException * @return ORMException
*/ */

View File

@ -136,6 +136,12 @@ class CompositePrimaryKeyTest extends \Doctrine\Tests\OrmFunctionalTestCase
$poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('key1' => 100)); $poi = $this->_em->find('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('key1' => 100));
} }
public function testUnrecognizedIdentifierFieldsOnGetReference()
{
$this->setExpectedException('Doctrine\ORM\ORMException', "Unrecognized identifier fields: 'key1'");
$poi = $this->_em->getReference('Doctrine\Tests\Models\Navigation\NavPointOfInterest', array('lat' => 10, 'long' => 20, 'key1' => 100));
}
/** /**
* @group DDC-1939 * @group DDC-1939
*/ */