Skip to content

Commit f891f16

Browse files
authored
fix(doctrine): isAssociationInverseSide before getMappedBy (#6197)
1 parent 56744dc commit f891f16

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/Doctrine/Orm/Metadata/Resource/DoctrineOrmLinkFactory.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,16 @@ public function createLinksFromRelations(Metadata $operation): array
6666
continue;
6767
}
6868

69+
if (!$doctrineMetadata->isAssociationInverseSide($property)) {
70+
continue;
71+
}
72+
73+
if (!($mappedBy = $doctrineMetadata->getAssociationMappedByTargetField($property))) {
74+
continue;
75+
}
76+
6977
$relationClass = $doctrineMetadata->getAssociationTargetClass($property);
70-
if (!($mappedBy = $doctrineMetadata->getAssociationMappedByTargetField($property)) || !$this->resourceClassResolver->isResourceClass($relationClass)) {
78+
if (!$this->resourceClassResolver->isResourceClass($relationClass)) {
7179
continue;
7280
}
7381

tests/Doctrine/Orm/Metadata/Resource/DoctrineOrmLinkFactoryTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ public function testCreateLinksFromRelations(): void
5151
$classMetadataProphecy->getAssociationMappedByTargetField('relatedNonResource')->willReturn('dummies');
5252
$classMetadataProphecy->getAssociationMappedByTargetField('relatedDummy')->willReturn(null);
5353
$classMetadataProphecy->getAssociationMappedByTargetField('relatedDummies')->willReturn('dummies');
54+
$classMetadataProphecy->isAssociationInverseSide('relatedNonResource')->willReturn(true);
55+
$classMetadataProphecy->isAssociationInverseSide('relatedDummy')->willReturn(true);
56+
$classMetadataProphecy->isAssociationInverseSide('relatedDummies')->willReturn(true);
57+
5458
$entityManagerProphecy = $this->prophesize(EntityManagerInterface::class);
5559
$entityManagerProphecy->getClassMetadata($class)->willReturn($classMetadataProphecy->reveal());
5660
$managerRegistryProphecy = $this->prophesize(ManagerRegistry::class);

tests/Fixtures/TestBundle/Doctrine/Orm/EntityManager.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,9 @@ public function createQuery($dql = ''): Query
4545

4646
return $this->wrapped->createQuery($dql);
4747
}
48+
49+
public function isUninitializedObject(mixed $value): bool
50+
{
51+
return true;
52+
}
4853
}

0 commit comments

Comments
 (0)