1
0
mirror of synced 2024-12-14 23:26:04 +03:00

[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:
Benjamin Eberlei 2011-03-03 22:51:53 +01:00
parent 8b9f12d924
commit b2c7a9c7fc
3 changed files with 35 additions and 0 deletions

View File

@ -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;

View File

@ -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 . "'.");
}
} }

View File

@ -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
{
} }