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

SchemaValidator: Fix mapped superclass missing in discriminator map #8903

Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Tools/SchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public function validateClass(ClassMetadataInfo $class)
}
}

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

/**
* @group 8771
*/
public function testMappedSuperclassNotPresentInDiscriminator(): void
{
$class1 = $this->em->getClassMetadata(MappedSuperclass::class);
$ce = $this->validator->validateClass($class1);

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

/**
* @MappedSuperClass
*/
abstract class MappedSuperclass extends ParentEntity
{
}

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

/**
* @Entity
*/
class ChildEntity extends MappedSuperclass
{
}

/**
Expand Down