1
0
mirror of synced 2025-01-29 19:41:45 +03:00

Merge pull request #858 from schmittjoh/rsmBuilder

lifts an unnecessary restriction on ResultSetMappingBuilder
This commit is contained in:
Benjamin Eberlei 2014-02-08 16:23:18 +01:00
commit 8e3f4561c0
2 changed files with 31 additions and 2 deletions

View File

@ -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.
*

View File

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