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. (#8378)
  • Loading branch information
beberlei authored Apr 10, 2021
1 parent f57f33b commit 09a7d9f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/Doctrine/ORM/Tools/SchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

use function array_diff;
use function array_key_exists;
use function array_search;
use function array_values;
use function class_exists;
use function class_parents;
Expand Down Expand Up @@ -255,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 09a7d9f

Please sign in to comment.