diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/DiscriminatorMap.php b/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/DiscriminatorMap.php index cd1131a25..644e24443 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/DiscriminatorMap.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/DiscriminatorMap.php @@ -16,10 +16,10 @@ #[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY)] final class DiscriminatorMap implements Annotation { - /** @var array */ + /** @var array */ public $value; - /** @param array $value */ + /** @param array $value */ public function __construct(array $value) { $this->value = $value; diff --git a/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php b/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php index 780c0c600..061b0c9da 100644 --- a/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php +++ b/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php @@ -1470,7 +1470,7 @@ private function getClassDiscriminatorValues(ClassMetadata $metadata): array foreach ($metadata->subClasses as $className) { $key = array_search($className, $metadata->discriminatorMap); - if (! $key) { + if ($key === false) { continue; } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH2158Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH2158Test.php new file mode 100644 index 000000000..f01456ce2 --- /dev/null +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH2158Test.php @@ -0,0 +1,46 @@ +dm->persist($obj); + $this->dm->flush(); + + self::assertEquals($this->dm->find(GH2158Abstract::class, $obj->getId()), $obj); + } +} + +#[ODM\Document(collection: 'documents')] +#[ODM\InheritanceType('SINGLE_COLLECTION')] +#[ODM\DiscriminatorField('type')] +#[ODM\DiscriminatorMap([0 => GH2158FirstType::class, 1 => GH2158SecondType::class])] +abstract class GH2158Abstract +{ + /** @var string */ + #[ODM\Id] + protected $id; + + public function getId(): string + { + return $this->id; + } +} + +#[ODM\Document] +class GH2158FirstType extends GH2158Abstract +{ +} + +#[ODM\Document] +class GH2158SecondType extends GH2158Abstract +{ +}