Skip to content

Commit dac49cb

Browse files
committed
Revert "fix: missing eager joins on to-one relationships (#5992)"
This reverts commit 9848bd4.
1 parent 7837e09 commit dac49cb

File tree

5 files changed

+10
-41
lines changed

5 files changed

+10
-41
lines changed

features/json/relation.feature

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ Feature: JSON relations support
2525
"badFourthLevel": null,
2626
"id": 1,
2727
"level": 3,
28-
"test": true,
29-
"relatedDummies": []
28+
"test": true
3029
}
3130
"""
3231

src/Doctrine/Orm/Extension/EagerLoadingExtension.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ private function joinRelations(QueryBuilder $queryBuilder, QueryNameGeneratorInt
168168
if (
169169
null !== $parentAssociation
170170
&& isset($mapping['inversedBy'])
171-
&& $mapping['sourceEntity'] === $mapping['targetEntity']
172171
&& $mapping['inversedBy'] === $parentAssociation
173172
&& $mapping['type'] & ClassMetadata::TO_ONE
174173
) {

tests/Doctrine/Orm/Extension/EagerLoadingExtensionTest.php

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\Dummy;
3030
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\EmbeddableDummy;
3131
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\RelatedDummy;
32-
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\ThirdLevel;
3332
use ApiPlatform\Tests\Fixtures\TestBundle\Entity\UnknownDummy;
3433
use Doctrine\ORM\EntityManager;
3534
use Doctrine\ORM\Mapping\ClassMetadata;
@@ -141,7 +140,6 @@ public function testApplyToItem(): void
141140
$propertyNameCollectionFactoryProphecy->create(RelatedDummy::class)->willReturn($relatedNameCollection)->shouldBeCalled();
142141
$propertyNameCollectionFactoryProphecy->create(EmbeddableDummy::class)->willReturn($relatedEmbedableCollection)->shouldBeCalled();
143142
$propertyNameCollectionFactoryProphecy->create(UnknownDummy::class)->willReturn(new PropertyNameCollection(['id']))->shouldBeCalled();
144-
$propertyNameCollectionFactoryProphecy->create(ThirdLevel::class)->willReturn(new PropertyNameCollection(['id']))->shouldBeCalled();
145143

146144
$propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
147145
$relationPropertyMetadata = new ApiProperty();
@@ -153,7 +151,6 @@ public function testApplyToItem(): void
153151
$propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummy4', $callContext)->willReturn($relationPropertyMetadata)->shouldBeCalled();
154152
$propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummy5', $callContext)->willReturn($relationPropertyMetadata)->shouldBeCalled();
155153
$propertyMetadataFactoryProphecy->create(Dummy::class, 'singleInheritanceRelation', $callContext)->willReturn($relationPropertyMetadata)->shouldBeCalled();
156-
$propertyMetadataFactoryProphecy->create(Dummy::class, 'relatedDummies', $callContext)->willReturn($relationPropertyMetadata)->shouldBeCalled();
157154

158155
$idPropertyMetadata = new ApiProperty();
159156
$idPropertyMetadata = $idPropertyMetadata->withIdentifier(true);
@@ -172,9 +169,7 @@ public function testApplyToItem(): void
172169
$propertyMetadataFactoryProphecy->create(RelatedDummy::class, 'notindatabase', $callContext)->willReturn($notInDatabasePropertyMetadata)->shouldBeCalled();
173170
$propertyMetadataFactoryProphecy->create(RelatedDummy::class, 'notreadable', $callContext)->willReturn($notReadablePropertyMetadata)->shouldBeCalled();
174171
$propertyMetadataFactoryProphecy->create(RelatedDummy::class, 'relation', $callContext)->willReturn($relationPropertyMetadata)->shouldBeCalled();
175-
$propertyMetadataFactoryProphecy->create(RelatedDummy::class, 'thirdLevel', $callContext)->willReturn($relationPropertyMetadata)->shouldBeCalled();
176172
$propertyMetadataFactoryProphecy->create(UnknownDummy::class, 'id', $callContext)->willReturn($idPropertyMetadata)->shouldBeCalled();
177-
$propertyMetadataFactoryProphecy->create(ThirdLevel::class, 'id', $callContext)->willReturn($idPropertyMetadata)->shouldBeCalled();
178173

179174
$queryBuilderProphecy = $this->prophesize(QueryBuilder::class);
180175

@@ -186,7 +181,6 @@ public function testApplyToItem(): void
186181
'relatedDummy4' => ['fetch' => ClassMetadataInfo::FETCH_EAGER, 'targetEntity' => UnknownDummy::class],
187182
'relatedDummy5' => ['fetch' => ClassMetadataInfo::FETCH_LAZY, 'targetEntity' => UnknownDummy::class],
188183
'singleInheritanceRelation' => ['fetch' => ClassMetadataInfo::FETCH_EAGER, 'targetEntity' => AbstractDummy::class],
189-
'relatedDummies' => ['fetch' => ClassMetadataInfo::FETCH_EAGER, 'targetEntity' => RelatedDummy::class],
190184
];
191185

192186
$relatedClassMetadataProphecy = $this->prophesize(ClassMetadata::class);
@@ -200,7 +194,6 @@ public function testApplyToItem(): void
200194

201195
$relatedClassMetadataProphecy->associationMappings = [
202196
'relation' => ['fetch' => ClassMetadataInfo::FETCH_EAGER, 'joinColumns' => [['nullable' => false]], 'targetEntity' => UnknownDummy::class],
203-
'thirdLevel' => ['fetch' => ClassMetadataInfo::FETCH_EAGER, 'targetEntity' => ThirdLevel::class, 'sourceEntity' => RelatedDummy::class, 'inversedBy' => 'relatedDummies', 'type' => ClassMetadata::TO_ONE],
204197
];
205198

206199
$relatedClassMetadataProphecy->embeddedClasses = ['embeddedDummy' => ['class' => EmbeddableDummy::class]];
@@ -211,38 +204,26 @@ public function testApplyToItem(): void
211204
$unknownClassMetadataProphecy = $this->prophesize(ClassMetadata::class);
212205
$unknownClassMetadataProphecy->associationMappings = [];
213206

214-
$thirdLevelMetadataProphecy = $this->prophesize(ClassMetadata::class);
215-
$thirdLevelMetadataProphecy->associationMappings = [];
216-
217207
$emProphecy = $this->prophesize(EntityManager::class);
218208
$emProphecy->getClassMetadata(Dummy::class)->shouldBeCalled()->willReturn($classMetadataProphecy->reveal());
219209
$emProphecy->getClassMetadata(RelatedDummy::class)->shouldBeCalled()->willReturn($relatedClassMetadataProphecy->reveal());
220210
$emProphecy->getClassMetadata(AbstractDummy::class)->shouldBeCalled()->willReturn($singleInheritanceClassMetadataProphecy->reveal());
221211
$emProphecy->getClassMetadata(UnknownDummy::class)->shouldBeCalled()->willReturn($unknownClassMetadataProphecy->reveal());
222-
$emProphecy->getClassMetadata(ThirdLevel::class)->shouldBeCalled()->willReturn($thirdLevelMetadataProphecy->reveal());
223212

224213
$queryBuilderProphecy->getRootAliases()->willReturn(['o']);
225214
$queryBuilderProphecy->getEntityManager()->willReturn($emProphecy);
226215
$queryBuilderProphecy->leftJoin('o.relatedDummy', 'relatedDummy_a1')->shouldBeCalledTimes(1);
227216
$queryBuilderProphecy->leftJoin('relatedDummy_a1.relation', 'relation_a2')->shouldBeCalledTimes(1);
228-
$queryBuilderProphecy->leftJoin('relatedDummy_a1.thirdLevel', 'thirdLevel_a3')->shouldBeCalledTimes(1);
229-
$queryBuilderProphecy->innerJoin('o.relatedDummy2', 'relatedDummy2_a4')->shouldBeCalledTimes(1);
230-
$queryBuilderProphecy->leftJoin('o.relatedDummy3', 'relatedDummy3_a5')->shouldBeCalledTimes(1);
231-
$queryBuilderProphecy->leftJoin('o.relatedDummy4', 'relatedDummy4_a6')->shouldBeCalledTimes(1);
232-
$queryBuilderProphecy->leftJoin('o.singleInheritanceRelation', 'singleInheritanceRelation_a7')->shouldBeCalledTimes(1);
233-
$queryBuilderProphecy->leftJoin('o.relatedDummies', 'relatedDummies_a8')->shouldBeCalledTimes(1);
234-
$queryBuilderProphecy->leftJoin('relatedDummies_a8.relation', 'relation_a9')->shouldBeCalledTimes(1);
235-
$queryBuilderProphecy->leftJoin('relatedDummies_a8.thirdLevel', 'thirdLevel_a10')->shouldBeCalledTimes(1);
217+
$queryBuilderProphecy->innerJoin('o.relatedDummy2', 'relatedDummy2_a3')->shouldBeCalledTimes(1);
218+
$queryBuilderProphecy->leftJoin('o.relatedDummy3', 'relatedDummy3_a4')->shouldBeCalledTimes(1);
219+
$queryBuilderProphecy->leftJoin('o.relatedDummy4', 'relatedDummy4_a5')->shouldBeCalledTimes(1);
220+
$queryBuilderProphecy->leftJoin('o.singleInheritanceRelation', 'singleInheritanceRelation_a6')->shouldBeCalledTimes(1);
236221
$queryBuilderProphecy->addSelect('partial relatedDummy_a1.{id,name,embeddedDummy.name}')->shouldBeCalledTimes(1);
237-
$queryBuilderProphecy->addSelect('partial thirdLevel_a3.{id}')->shouldBeCalledTimes(1);
238222
$queryBuilderProphecy->addSelect('partial relation_a2.{id}')->shouldBeCalledTimes(1);
239-
$queryBuilderProphecy->addSelect('partial relatedDummy2_a4.{id}')->shouldBeCalledTimes(1);
240-
$queryBuilderProphecy->addSelect('partial relatedDummy3_a5.{id}')->shouldBeCalledTimes(1);
241-
$queryBuilderProphecy->addSelect('partial relatedDummy4_a6.{id}')->shouldBeCalledTimes(1);
242-
$queryBuilderProphecy->addSelect('singleInheritanceRelation_a7')->shouldBeCalledTimes(1);
243-
$queryBuilderProphecy->addSelect('partial relatedDummies_a8.{id,name,embeddedDummy.name}')->shouldBeCalledTimes(1);
244-
$queryBuilderProphecy->addSelect('partial relation_a9.{id}')->shouldBeCalledTimes(1);
245-
$queryBuilderProphecy->addSelect('partial thirdLevel_a10.{id}')->shouldBeCalledTimes(1);
223+
$queryBuilderProphecy->addSelect('partial relatedDummy2_a3.{id}')->shouldBeCalledTimes(1);
224+
$queryBuilderProphecy->addSelect('partial relatedDummy3_a4.{id}')->shouldBeCalledTimes(1);
225+
$queryBuilderProphecy->addSelect('partial relatedDummy4_a5.{id}')->shouldBeCalledTimes(1);
226+
$queryBuilderProphecy->addSelect('singleInheritanceRelation_a6')->shouldBeCalledTimes(1);
246227
$queryBuilderProphecy->getDQLPart('join')->willReturn([]);
247228
$queryBuilderProphecy->getDQLPart('select')->willReturn([]);
248229

tests/Fixtures/TestBundle/Entity/RelatedDummy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class RelatedDummy extends ParentDummy implements \Stringable
8686
#[ApiFilter(filterClass: DateFilter::class)]
8787
public $dummyDate;
8888

89-
#[ORM\ManyToOne(targetEntity: ThirdLevel::class, cascade: ['persist'], inversedBy: 'relatedDummies')]
89+
#[ORM\ManyToOne(targetEntity: ThirdLevel::class, cascade: ['persist'])]
9090
#[Groups(['barcelona', 'chicago', 'friends'])]
9191
public ?ThirdLevel $thirdLevel = null;
9292

tests/Fixtures/TestBundle/Entity/ThirdLevel.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
use ApiPlatform\Metadata\ApiResource;
1717
use ApiPlatform\Metadata\Get;
1818
use ApiPlatform\Metadata\Link;
19-
use Doctrine\Common\Collections\ArrayCollection;
20-
use Doctrine\Common\Collections\Collection;
2119
use Doctrine\ORM\Mapping as ORM;
2220
use Symfony\Component\Serializer\Annotation\Groups;
2321

@@ -53,14 +51,6 @@ class ThirdLevel
5351
#[ORM\ManyToOne(targetEntity: FourthLevel::class, cascade: ['persist'])]
5452
public $badFourthLevel;
5553

56-
#[ORM\OneToMany(mappedBy: 'thirdLevel', targetEntity: RelatedDummy::class)]
57-
public Collection|iterable $relatedDummies;
58-
59-
public function __construct()
60-
{
61-
$this->relatedDummies = new ArrayCollection();
62-
}
63-
6454
public function getId(): ?int
6555
{
6656
return $this->id;

0 commit comments

Comments
 (0)