Skip to content

Commit

Permalink
Fix doctrine#9095 by re-applying doctrine#9096
Browse files Browse the repository at this point in the history
Since doctrine#10411 has been merged, no more need to specify all intermediate
abstract entity classes.

Thus, we can relax the schema validator check as requested in doctrine#9095. The
reasons given in doctrine#9142 no longer apply.

Fixes doctrine#9095
Closes doctrine#9096
  • Loading branch information
mpdude authored and greg0ire committed Feb 5, 2023
1 parent 3843d7e commit 6f6a761
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Tools/SchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public function validateClass(ClassMetadataInfo $class)
}
}

if (! $class->isInheritanceTypeNone() && ! $class->isRootEntity() && ! $class->isMappedSuperclass && array_search($class->name, $class->discriminatorMap, true) === false) {
if (! $class->isInheritanceTypeNone() && ! $class->isRootEntity() && ($class->reflClass !== null && ! $class->reflClass->isAbstract()) && ! $class->isMappedSuperclass && array_search($class->name, $class->discriminatorMap, true) === 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.';
Expand Down
33 changes: 33 additions & 0 deletions tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,14 @@ public function testMappedSuperclassNotPresentInDiscriminator(): void

$this->assertEquals([], $ce);
}

public function testAbstractChildClassNotPresentInDiscriminator(): void
{
$class1 = $this->em->getClassMetadata(Issue9095AbstractChild::class);
$ce = $this->validator->validateClass($class1);

self::assertEmpty($ce);
}
}

/** @MappedSuperclass */
Expand Down Expand Up @@ -643,3 +651,28 @@ class EmbeddableWithAssociation
*/
private $cart;
}

/**
* @Entity
* @InheritanceType("SINGLE_TABLE")
* @DiscriminatorMap({"child" = Issue9095Child::class})
*/
abstract class Issue9095Parent
{
/**
* @var mixed
* @Id
* @Column
*/
protected $key;
}

/** @Entity */
abstract class Issue9095AbstractChild extends Issue9095Parent
{
}

/** @Entity */
class Issue9095Child extends Issue9095AbstractChild
{
}

0 comments on commit 6f6a761

Please sign in to comment.