diff --git a/src/Bridge/Doctrine/MongoDbOdm/PropertyInfo/DoctrineExtractor.php b/src/Bridge/Doctrine/MongoDbOdm/PropertyInfo/DoctrineExtractor.php index 3325392b5da..8286097ecef 100644 --- a/src/Bridge/Doctrine/MongoDbOdm/PropertyInfo/DoctrineExtractor.php +++ b/src/Bridge/Doctrine/MongoDbOdm/PropertyInfo/DoctrineExtractor.php @@ -65,6 +65,10 @@ public function getTypes($class, $property, array $context = []) if ($metadata->hasAssociation($property)) { $class = $metadata->getAssociationTargetClass($property); + if (null === $class) { + return null; + } + if ($metadata->isSingleValuedAssociation($property)) { $nullable = $metadata instanceof MongoDbClassMetadata && $metadata->isNullable($property); diff --git a/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/DoctrineExtractorTest.php b/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/DoctrineExtractorTest.php index 20b864155ea..ef799350f49 100644 --- a/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/DoctrineExtractorTest.php +++ b/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/DoctrineExtractorTest.php @@ -74,6 +74,7 @@ public function testTestGetPropertiesWithEmbedded(): void 'id', 'embedOne', 'embedMany', + 'embedManyOmittingTargetDocument', ], $this->createExtractor()->getProperties(DoctrineWithEmbedded::class) ); @@ -197,6 +198,18 @@ public function testGeneratedValueNotWritable() $this->assertNull($extractor->isReadable(DoctrineGeneratedValue::class, 'foo')); } + public function testGetTypesWithEmbedManyOmittingTargetDocument(): void + { + $expectedTypes = null; + + $actualTypes = $this->createExtractor()->getTypes( + DoctrineWithEmbedded::class, + 'embedManyOmittingTargetDocument' + ); + + self::assertEquals($expectedTypes, $actualTypes); + } + private function createExtractor(): DoctrineExtractor { $config = DoctrineMongoDbOdmSetup::createAnnotationMetadataConfiguration([__DIR__.\DIRECTORY_SEPARATOR.'Fixtures'], true); diff --git a/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/Fixtures/DoctrineWithEmbedded.php b/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/Fixtures/DoctrineWithEmbedded.php index 6854ef44a89..085d0255f01 100644 --- a/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/Fixtures/DoctrineWithEmbedded.php +++ b/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/Fixtures/DoctrineWithEmbedded.php @@ -39,4 +39,9 @@ class DoctrineWithEmbedded * @EmbedMany(targetDocument=DoctrineEmbeddable::class) */ protected $embedMany; + + /** + * @EmbedMany + */ + protected $embedManyOmittingTargetDocument; }