Skip to content

Commit

Permalink
[GH-6578] Add validation that inherited entity class is mapped in dis…
Browse files Browse the repository at this point in the history
…criminator.
  • Loading branch information
beberlei committed Dec 7, 2020
1 parent 242cf1a commit 3c5c8a0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/Doctrine/ORM/Tools/SchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
use Doctrine\DBAL\Types\Type;

use function array_search;
use function count;

/**
Expand Down Expand Up @@ -256,6 +258,12 @@ public function validateClass(ClassMetadataInfo $class)
}
}

if (! $class->isInheritanceTypeNone() && ! $class->isRootEntity() && array_search($class->name, $class->discriminatorMap) === false) {
$ce[] = "Entity class '" . $class->name . "' is part of inheritance hierarchy, but is " .
"not mapped in the root entity '" . $class->rootEntityName . "' discriminator map. " .
'All subclasses must be listed in the discriminator map.';
}

foreach ($class->subClasses as $subClass) {
if (!in_array($class->name, class_parents($subClass))) {
$ce[] = "According to the discriminator map class '" . $subClass . "' has to be a child ".
Expand Down

0 comments on commit 3c5c8a0

Please sign in to comment.