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 */