[DDC-1050] Throw exception when trying to define inheritance information on a mapped superclass. It is not a valid use-case.
This commit is contained in:
parent
8b9f12d924
commit
b2c7a9c7fc
@ -325,6 +325,8 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
|
|||||||
if (!$class->discriminatorColumn) {
|
if (!$class->discriminatorColumn) {
|
||||||
throw MappingException::missingDiscriminatorColumn($class->name);
|
throw MappingException::missingDiscriminatorColumn($class->name);
|
||||||
}
|
}
|
||||||
|
} else if ($class->isMappedSuperclass && (count($class->discriminatorMap) || $class->discriminatorColumn)) {
|
||||||
|
throw MappingException::noInheritanceOnMappedSuperClass($class->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->loadedMetadata[$className] = $class;
|
$this->loadedMetadata[$className] = $class;
|
||||||
|
@ -270,4 +270,9 @@ class MappingException extends \Doctrine\ORM\ORMException
|
|||||||
{
|
{
|
||||||
return new self("Many-to-many or one-to-many associations are not allowed to be identifier in '$className#$field'.");
|
return new self("Many-to-many or one-to-many associations are not allowed to be identifier in '$className#$field'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function noInheritanceOnMappedSuperClass($className)
|
||||||
|
{
|
||||||
|
return new self("Its not supported to define inheritance information on a mapped superclass '" . $className . "'.");
|
||||||
|
}
|
||||||
}
|
}
|
@ -149,6 +149,24 @@ class AnnotationDriverTest extends AbstractMappingDriverTest
|
|||||||
"mapped superclass 'Doctrine\Tests\ORM\Mapping\InvalidMappedSuperClass#users'");
|
"mapped superclass 'Doctrine\Tests\ORM\Mapping\InvalidMappedSuperClass#users'");
|
||||||
$usingInvalidMsc = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\UsingInvalidMappedSuperClass');
|
$usingInvalidMsc = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\UsingInvalidMappedSuperClass');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-1050
|
||||||
|
*/
|
||||||
|
public function testInvalidMappedSuperClassWithInheritanceInformation()
|
||||||
|
{
|
||||||
|
$annotationDriver = $this->_loadDriver();
|
||||||
|
|
||||||
|
$em = $this->_getTestEntityManager();
|
||||||
|
$em->getConfiguration()->setMetadataDriverImpl($annotationDriver);
|
||||||
|
$factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
|
||||||
|
$factory->setEntityManager($em);
|
||||||
|
|
||||||
|
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException',
|
||||||
|
"Its not supported to define inheritance information on a mapped ".
|
||||||
|
"superclass 'Doctrine\Tests\ORM\Mapping\MappedSuperClassInheritence'.");
|
||||||
|
$usingInvalidMsc = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\MappedSuperClassInheritence');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -180,4 +198,14 @@ class UsingInvalidMappedSuperClass extends InvalidMappedSuperClass
|
|||||||
* @Id @Column(type="integer") @GeneratedValue
|
* @Id @Column(type="integer") @GeneratedValue
|
||||||
*/
|
*/
|
||||||
private $id;
|
private $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @MappedSuperclass
|
||||||
|
* @InheritanceType("JOINED")
|
||||||
|
* @DiscriminatorMap({"test" = "ColumnWithoutType"})
|
||||||
|
*/
|
||||||
|
class MappedSuperClassInheritence
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user