Skip to content

Commit

Permalink
fix(doctrine): isAssociationInverseSide before getMappedBy (#6197)
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka authored Mar 5, 2024
1 parent 56744dc commit f891f16
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Doctrine/Orm/Metadata/Resource/DoctrineOrmLinkFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,16 @@ public function createLinksFromRelations(Metadata $operation): array
continue;
}

if (!$doctrineMetadata->isAssociationInverseSide($property)) {
continue;
}

if (!($mappedBy = $doctrineMetadata->getAssociationMappedByTargetField($property))) {
continue;
}

$relationClass = $doctrineMetadata->getAssociationTargetClass($property);
if (!($mappedBy = $doctrineMetadata->getAssociationMappedByTargetField($property)) || !$this->resourceClassResolver->isResourceClass($relationClass)) {
if (!$this->resourceClassResolver->isResourceClass($relationClass)) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public function testCreateLinksFromRelations(): void
$classMetadataProphecy->getAssociationMappedByTargetField('relatedNonResource')->willReturn('dummies');
$classMetadataProphecy->getAssociationMappedByTargetField('relatedDummy')->willReturn(null);
$classMetadataProphecy->getAssociationMappedByTargetField('relatedDummies')->willReturn('dummies');
$classMetadataProphecy->isAssociationInverseSide('relatedNonResource')->willReturn(true);
$classMetadataProphecy->isAssociationInverseSide('relatedDummy')->willReturn(true);
$classMetadataProphecy->isAssociationInverseSide('relatedDummies')->willReturn(true);

$entityManagerProphecy = $this->prophesize(EntityManagerInterface::class);
$entityManagerProphecy->getClassMetadata($class)->willReturn($classMetadataProphecy->reveal());
$managerRegistryProphecy = $this->prophesize(ManagerRegistry::class);
Expand Down
5 changes: 5 additions & 0 deletions tests/Fixtures/TestBundle/Doctrine/Orm/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@ public function createQuery($dql = ''): Query

return $this->wrapped->createQuery($dql);
}

public function isUninitializedObject(mixed $value): bool
{
return true;
}
}

0 comments on commit f891f16

Please sign in to comment.