Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6386dec

Browse files
committedAug 9, 2021
Fix mapped superclass missing in discriminator map
1 parent 4fa2f6b commit 6386dec

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-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

+41
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,47 @@ 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(ChildEntity::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+
{
242+
202243
}
203244

204245
/**

0 commit comments

Comments
 (0)
Please sign in to comment.