DDC-1156 - Do not throw exception for mapped superclass in middle of inheritance hierachy anymore.
This commit is contained in:
parent
543432bf53
commit
22826ac10d
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -264,4 +279,35 @@ class AnnotationParent
|
||||
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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user