Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GH-6578] Add validation that inherited entity class is mapped in discriminator. #8378

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @beberlei,

shouldn't we skip this for abstract classes?
They were allowed to not be a part of mapping, but just be parent class for classes that are mapped in the root entity.

Now with update to Doctrine version 2.9.1 we are getting this error by schema validator

Entity class 'App\Entity\Order\CardSuborder' is part of inheritance hierarchy, but is not mapped in the root entity 'App\Entity\Suborder' discriminator map. All subclasses must be listed in the discriminator map.

where Suborder is a root entity, and CardSuborder is an abstract class extended from it, and then we have other not abstract classes extended from CardSuborder, and mapped in Suborder.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue for me in #8771; any solution for this, @beberlei?

$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