Skip to content

Commit 7fcab3d

Browse files
authored
Merge pull request #8903 from olsavmic/fix-schema-validator-for-mapped-superclass-inheritance
SchemaValidator: Fix mapped superclass missing in discriminator map
2 parents 316ba5f + 5685dc0 commit 7fcab3d

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
@@ -255,7 +255,7 @@ public function validateClass(ClassMetadataInfo $class)
255255
}
256256
}
257257

258-
if (! $class->isInheritanceTypeNone() && ! $class->isRootEntity() && array_search($class->name, $class->discriminatorMap) === false) {
258+
if (! $class->isInheritanceTypeNone() && ! $class->isRootEntity() && ! $class->isMappedSuperclass && array_search($class->name, $class->discriminatorMap) === false) {
259259
$ce[] = "Entity class '" . $class->name . "' is part of inheritance hierarchy, but is " .
260260
"not mapped in the root entity '" . $class->rootEntityName . "' discriminator map. " .
261261
'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
@@ -199,6 +199,46 @@ public function testInvalidAssociationInsideEmbeddable(): void
199199
$ce
200200
);
201201
}
202+
203+
/**
204+
* @group 8771
205+
*/
206+
public function testMappedSuperclassNotPresentInDiscriminator(): void
207+
{
208+
$class1 = $this->em->getClassMetadata(MappedSuperclass::class);
209+
$ce = $this->validator->validateClass($class1);
210+
211+
$this->assertEquals([], $ce);
212+
}
213+
}
214+
215+
/**
216+
* @MappedSuperClass
217+
*/
218+
abstract class MappedSuperclass extends ParentEntity
219+
{
220+
}
221+
222+
/**
223+
* @Entity
224+
* @InheritanceType("SINGLE_TABLE")
225+
* @DiscriminatorMap({"child" = ChildEntity::class})
226+
*/
227+
abstract class ParentEntity
228+
{
229+
/**
230+
* @var mixed
231+
* @Id
232+
* @Column
233+
*/
234+
protected $key;
235+
}
236+
237+
/**
238+
* @Entity
239+
*/
240+
class ChildEntity extends MappedSuperclass
241+
{
202242
}
203243

204244
/**

0 commit comments

Comments
 (0)