From 6523f7f59ed54a2b9e80d2066165bb26282669b9 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sun, 27 May 2012 17:11:21 +0200 Subject: [PATCH] [DDC-1777] Fix bug in BasicEntityPersister#exists() when no primary key is set. --- .../ORM/Persisters/BasicEntityPersister.php | 4 ++++ .../Functional/ClassTableInheritanceTest.php | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index a11c26b84..d51e2fe51 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -1524,6 +1524,10 @@ class BasicEntityPersister { $criteria = $this->_class->getIdentifierValues($entity); + if ( ! $criteria) { + return false; + } + if ($extraConditions) { $criteria = array_merge($criteria, $extraConditions); } diff --git a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php index 83320dfc7..bd6c7943f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ClassTableInheritanceTest.php @@ -448,4 +448,23 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $manager = $this->_em->find('Doctrine\Tests\Models\Company\CompanyManager', $manager->getId()); $this->assertEquals(1, count($manager->getFriends())); } + + /** + * @group DDC-1777 + */ + public function testExistsSubclass() + { + $manager = new CompanyManager(); + $manager->setName('gblanco'); + $manager->setSalary(1234); + $manager->setTitle('Awesome!'); + $manager->setDepartment('IT'); + + $this->assertFalse($this->_em->getUnitOfWork()->getEntityPersister(get_class($manager))->exists($manager)); + + $this->_em->persist($manager); + $this->_em->flush(); + + $this->assertTrue($this->_em->getUnitOfWork()->getEntityPersister(get_class($manager))->exists($manager)); + } }