Skip to content

Commit

Permalink
[doctrineGH-6578] Add validation that inherited entity class is mappe…
Browse files Browse the repository at this point in the history
…d in discriminator.
  • Loading branch information
beberlei committed Dec 6, 2020
1 parent 242cf1a commit 65c82aa
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/Doctrine/ORM/Tools/SchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,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 65c82aa

Please sign in to comment.