From 8ae48ad9db4ab28c93d09cc9e645afc2e5e28523 Mon Sep 17 00:00:00 2001 From: "Johannes M. Schmitt" Date: Sat, 23 Nov 2013 19:44:33 +0100 Subject: [PATCH 1/2] lifts an unnecessary restriction on ResultSetMappingBuilder --- lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php b/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php index ad159e0a5..03fa9620f 100644 --- a/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php +++ b/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php @@ -142,8 +142,8 @@ class ResultSetMappingBuilder extends ResultSetMapping $classMetadata = $this->em->getClassMetadata($class); $platform = $this->em->getConnection()->getDatabasePlatform(); - if ($classMetadata->isInheritanceTypeSingleTable() || $classMetadata->isInheritanceTypeJoined()) { - throw new \InvalidArgumentException('ResultSetMapping builder does not currently support inheritance.'); + if ( ! $this->isInheritanceSupported($classMetadata)) { + throw new \InvalidArgumentException('ResultSetMapping builder does not currently support your inheritance scheme.'); } @@ -179,6 +179,16 @@ class ResultSetMappingBuilder extends ResultSetMapping } } + private function isInheritanceSupported(ClassMetadataInfo $classMetadata) + { + if ($classMetadata->isInheritanceTypeSingleTable() + && in_array($classMetadata->name, $classMetadata->discriminatorMap, true)) { + return true; + } + + return ! ($classMetadata->isInheritanceTypeSingleTable() || $classMetadata->isInheritanceTypeJoined()); + } + /** * Gets column alias for a given column. * From 87b415566559eaf8bed54152560e33b021902708 Mon Sep 17 00:00:00 2001 From: Johannes Schmitt Date: Sat, 4 Jan 2014 18:06:16 +0100 Subject: [PATCH 2/2] adds test for ResultSetMappingBuilder restriction --- .../Tests/ORM/Functional/NativeQueryTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php b/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php index bbdefb07d..73e222118 100644 --- a/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php @@ -313,6 +313,25 @@ class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals($user->name, $address->getUser()->getName()); } + /** + * @group rsm-sti + */ + public function testConcreteClassInSingleTableInheritanceSchemaWithRSMBuilderIsFine() + { + $rsm = new ResultSetMappingBuilder($this->_em); + $rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\Company\CompanyFixContract', 'c'); + } + + /** + * @group rsm-sti + */ + public function testAbstractClassInSingleTableInheritanceSchemaWithRSMBuilderThrowsException() + { + $this->setExpectedException('\InvalidArgumentException', 'ResultSetMapping builder does not currently support your inheritance scheme.'); + $rsm = new ResultSetMappingBuilder($this->_em); + $rsm->addRootEntityFromClassMetadata('Doctrine\Tests\Models\Company\CompanyContract', 'c'); + } + /** * @expectedException \InvalidArgumentException */