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

Conversation

beberlei
Copy link
Member

@beberlei beberlei commented Dec 6, 2020

Without tests as not failing all the schema validator tests with our existing models is proof enough, i flipped a condition to see it breaking hard.

Supersedes #6578
Fixes #6558

@beberlei beberlei changed the base branch from 2.8.x to 2.9.x December 6, 2020 21:40
@beberlei beberlei force-pushed the GH-6578-EntityHierarchyDiscriminatorMapValidation branch from 65c82aa to 8d1a5ce Compare December 7, 2020 07:32
@beberlei beberlei force-pushed the GH-6578-EntityHierarchyDiscriminatorMapValidation branch from 8d1a5ce to 3c5c8a0 Compare December 7, 2020 21:13
@beberlei beberlei added this to the 2.9.0 milestone Feb 28, 2021
@beberlei beberlei merged commit 09a7d9f into doctrine:2.9.x Apr 10, 2021
@beberlei beberlei deleted the GH-6578-EntityHierarchyDiscriminatorMapValidation branch April 10, 2021 16:13
@@ -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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants