Skip to content

Commit

Permalink
fix(doctrine): denormalization of properties with embeds many which o…
Browse files Browse the repository at this point in the history
…mit target document directive
  • Loading branch information
wuchen90 committed Jun 10, 2021
1 parent e32b4e8 commit d5b8e65
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function testTestGetPropertiesWithEmbedded(): void
'id',
'embedOne',
'embedMany',
'embedManyOmittingTargetDocument',
],
$this->createExtractor()->getProperties(DoctrineWithEmbedded::class)
);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ class DoctrineWithEmbedded
* @EmbedMany(targetDocument=DoctrineEmbeddable::class)
*/
protected $embedMany;

/**
* @EmbedMany
*/
protected $embedManyOmittingTargetDocument;
}

0 comments on commit d5b8e65

Please sign in to comment.