From a0a81db045359496974a490bb6e37bf765106a3c Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Thu, 30 Jun 2011 20:57:29 +0200 Subject: [PATCH] DDC-1204, DDC-1203 - No need to throw this exception for abstract classes anymore --- lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php | 2 +- lib/Doctrine/ORM/Mapping/MappingException.php | 3 ++- .../Tests/ORM/Mapping/BasicInheritanceMappingTest.php | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 3f65da3c5..8bfda6450 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -327,7 +327,7 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface if (!$class->discriminatorColumn) { throw MappingException::missingDiscriminatorColumn($class->name); } - } else if ($parent && !in_array($class->name, array_values($class->discriminatorMap))) { + } else if ($parent && !$class->reflClass->isAbstract() && !in_array($class->name, array_values($class->discriminatorMap))) { // enforce discriminator map for all entities of an inheritance hierachy, otherwise problems will occur. throw MappingException::mappedClassNotPartOfDiscriminatorMap($class->name, $class->rootEntityName); } diff --git a/lib/Doctrine/ORM/Mapping/MappingException.php b/lib/Doctrine/ORM/Mapping/MappingException.php index 9c65ad928..5bedf3a06 100644 --- a/lib/Doctrine/ORM/Mapping/MappingException.php +++ b/lib/Doctrine/ORM/Mapping/MappingException.php @@ -289,7 +289,8 @@ class MappingException extends \Doctrine\ORM\ORMException { return new self( "Entity '" . $className . "' has to be part of the descriminator map of '" . $rootClassName . "' " . - "to be properly mapped in the inheritance hierachy. If you want to avoid instantiation of this type mark it abstract." + "to be properly mapped in the inheritance hierachy. Alternatively you can make '".$className."' an abstract class " . + "to avoid this exception from occuring." ); } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php index 91ebbd99b..d5aac63f9 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php @@ -85,7 +85,7 @@ class BasicInheritanceMappingTest extends \Doctrine\Tests\OrmTestCase */ public function testUnmappedEntityInHierachy() { - $this->setExpectedException('Doctrine\ORM\Mapping\MappingException', "Entity 'Doctrine\Tests\ORM\Mapping\HierachyBEntity' has to be part of the descriminator map of 'Doctrine\Tests\ORM\Mapping\HierachyBase' to be properly mapped in the inheritance hierachy. If you want to avoid instantiation of this type mark it abstract."); + $this->setExpectedException('Doctrine\ORM\Mapping\MappingException', "Entity 'Doctrine\Tests\ORM\Mapping\HierachyBEntity' has to be part of the descriminator map of 'Doctrine\Tests\ORM\Mapping\HierachyBase' to be properly mapped in the inheritance hierachy. Alternatively you can make 'Doctrine\Tests\ORM\Mapping\HierachyBEntity' an abstract class to avoid this exception from occuring."); $class = $this->_factory->getMetadataFor(__NAMESPACE__ . '\\HierachyE'); } @@ -209,7 +209,7 @@ abstract class HierachyASuperclass extends HierachyBase /** * @Entity */ -abstract class HierachyBEntity extends HierachyBase +class HierachyBEntity extends HierachyBase { /** @Column(type="string") */ public $b;