From 8c6607532b2d98fd9041a36d3a0b5547f2a9a751 Mon Sep 17 00:00:00 2001 From: Sergio Santoro Date: Sun, 10 May 2015 00:28:28 +0200 Subject: [PATCH] EntityManager#getReference throw ORMException for unrecognized id - Unreachable statements have been removed - Throw ORMException for unrecognized identifier field (same behavior as EntityManager#find) --- lib/Doctrine/ORM/EntityManager.php | 9 +++++---- lib/Doctrine/ORM/ORMException.php | 2 +- .../Tests/ORM/Functional/CompositePrimaryKeyTest.php | 6 ++++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/EntityManager.php b/lib/Doctrine/ORM/EntityManager.php index 685fc0d71..ccbc92470 100644 --- a/lib/Doctrine/ORM/EntityManager.php +++ b/lib/Doctrine/ORM/EntityManager.php @@ -482,6 +482,11 @@ use Doctrine\Common\Util\ClassUtils; } $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. @@ -493,10 +498,6 @@ use Doctrine\Common\Util\ClassUtils; return $this->find($entityName, $sortedId); } - if ( ! is_array($sortedId)) { - $sortedId = array($class->identifier[0] => $sortedId); - } - $entity = $this->proxyFactory->getProxy($class->name, $sortedId); $this->unitOfWork->registerManaged($entity, $sortedId, array()); diff --git a/lib/Doctrine/ORM/ORMException.php b/lib/Doctrine/ORM/ORMException.php index d4a729d7e..6d8a6d631 100644 --- a/lib/Doctrine/ORM/ORMException.php +++ b/lib/Doctrine/ORM/ORMException.php @@ -296,7 +296,7 @@ class ORMException extends Exception /** * @param string $className - * @param string $fieldName + * @param string[] $fieldNames * * @return ORMException */ diff --git a/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php index 7967ecce0..2e1cedb39 100644 --- a/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/CompositePrimaryKeyTest.php @@ -136,6 +136,12 @@ class CompositePrimaryKeyTest extends \Doctrine\Tests\OrmFunctionalTestCase $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 */