1
0
mirror of synced 2025-01-18 06:21:40 +03:00

DDC-1156 - Do not throw exception for mapped superclass in middle of inheritance hierachy anymore.

This commit is contained in:
Benjamin Eberlei 2011-06-05 15:00:49 +02:00
parent 543432bf53
commit 22826ac10d
2 changed files with 48 additions and 1 deletions

View File

@ -325,7 +325,8 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
if (!$class->discriminatorColumn) {
throw MappingException::missingDiscriminatorColumn($class->name);
}
} else if ($class->isMappedSuperclass && (count($class->discriminatorMap) || $class->discriminatorColumn)) {
} else if ($class->isMappedSuperclass && $class->name == $class->rootEntityName && (count($class->discriminatorMap) || $class->discriminatorColumn)) {
// second condition is necessary for mapped superclasses in the middle of an inheritance hierachy
throw MappingException::noInheritanceOnMappedSuperClass($class->name);
}

View File

@ -184,6 +184,21 @@ class AnnotationDriverTest extends AbstractMappingDriverTest
$cm = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\AnnotationParent');
$this->assertEquals(array("postLoad" => array("postLoad"), "preUpdate" => array("preUpdate")), $cm->lifecycleCallbacks);
}
/**
* @group DDC-1156
*/
public function testMappedSuperclassInMiddleOfInheritanceHierachy()
{
$annotationDriver = $this->_loadDriver();
$em = $this->_getTestEntityManager();
$em->getConfiguration()->setMetadataDriverImpl($annotationDriver);
$factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
$factory->setEntityManager($em);
$cm = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\ChildEntity');
}
}
/**
@ -265,3 +280,34 @@ class AnnotationChild extends AnnotationParent
{
}
/**
* @Entity
* @InheritanceType("SINGLE_TABLE")
* @DiscriminatorMap({"s"="SuperEntity", "c"="ChildEntity"})
*/
class SuperEntity
{
/** @Id @Column(type="string") */
private $id;
}
/**
* @MappedSuperclass
*/
class MiddleMappedSuperclass extends SuperEntity
{
/** @Column(type="string") */
private $name;
}
/**
* @Entity
*/
class ChildEntity extends MiddleMappedSuperclass
{
/**
* @Column(type="string")
*/
private $text;
}