Skip to content

Commit bbb68d0

Browse files
authored
Fix SchemaValidator with abstract child class in discriminator map (#9096)
1 parent f346379 commit bbb68d0

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

lib/Doctrine/ORM/Tools/SchemaValidator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public function validateClass(ClassMetadataInfo $class)
239239
}
240240
}
241241

242-
if (! $class->isInheritanceTypeNone() && ! $class->isRootEntity() && ! $class->isMappedSuperclass && array_search($class->name, $class->discriminatorMap, true) === false) {
242+
if (! $class->isInheritanceTypeNone() && ! $class->isRootEntity() && ! $class->reflClass->isAbstract() && ! $class->isMappedSuperclass && array_search($class->name, $class->discriminatorMap, true) === false) {
243243
$ce[] = "Entity class '" . $class->name . "' is part of inheritance hierarchy, but is " .
244244
"not mapped in the root entity '" . $class->rootEntityName . "' discriminator map. " .
245245
'All subclasses must be listed in the discriminator map.';

tests/Doctrine/Tests/ORM/Tools/SchemaValidatorTest.php

+40
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,17 @@ public function testMappedSuperclassNotPresentInDiscriminator(): void
225225

226226
$this->assertEquals([], $ce);
227227
}
228+
229+
/**
230+
* @group 9095
231+
*/
232+
public function testAbstractChildClassNotPresentInDiscriminator(): void
233+
{
234+
$class1 = $this->em->getClassMetadata(Issue9095AbstractChild::class);
235+
$ce = $this->validator->validateClass($class1);
236+
237+
$this->assertEquals([], $ce);
238+
}
228239
}
229240

230241
/**
@@ -256,6 +267,35 @@ class ChildEntity extends MappedSuperclassEntity
256267
{
257268
}
258269

270+
/**
271+
* @Entity
272+
* @InheritanceType("SINGLE_TABLE")
273+
* @DiscriminatorMap({"child" = Issue9095Child::class})
274+
*/
275+
abstract class Issue9095Parent
276+
{
277+
/**
278+
* @var mixed
279+
* @Id
280+
* @Column
281+
*/
282+
protected $key;
283+
}
284+
285+
/**
286+
* @Entity
287+
*/
288+
abstract class Issue9095AbstractChild extends Issue9095Parent
289+
{
290+
}
291+
292+
/**
293+
* @Entity
294+
*/
295+
class Issue9095Child extends Issue9095AbstractChild
296+
{
297+
}
298+
259299
/**
260300
* @Entity
261301
*/

0 commit comments

Comments
 (0)