Skip to content

Commit 0ece408

Browse files
author
David Duquenoy
committed
FilterEagerLoadingExtension accepts joins with class name as join value
It is mainly useful to add left joins on reversed mapping.
1 parent ec4e0cb commit 0ece408

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/Bridge/Doctrine/Orm/Extension/FilterEagerLoadingExtension.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ private function getQueryBuilderWithNewAliases(QueryBuilder $queryBuilder, Query
135135
/** @var Join $joinPart */
136136
$joinString = str_replace($aliases, $replacements, $joinPart->getJoin());
137137
$pos = strpos($joinString, '.');
138+
if (false === $pos) {
139+
continue;
140+
}
138141
$alias = substr($joinString, 0, $pos);
139142
$association = substr($joinString, $pos + 1);
140143
$condition = str_replace($aliases, $replacements, $joinPart->getCondition());

tests/Bridge/Doctrine/Orm/Extension/FilterEagerLoadingExtensionTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ public function testFetchEagerWithNoForceEager()
302302
{
303303
$resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataFactoryInterface::class);
304304
$resourceMetadataFactoryProphecy->create(CompositeRelation::class)->willReturn(new ResourceMetadata(CompositeRelation::class));
305+
$resourceMetadataFactoryProphecy->create(DummyCar::class)->willReturn(new ResourceMetadata(DummyCar::class));
305306

306307
$classMetadata = new ClassMetadataInfo(CompositeRelation::class);
307308
$classMetadata->isIdentifierComposite = true;
@@ -322,6 +323,7 @@ public function testFetchEagerWithNoForceEager()
322323
->innerJoin('o.compositeItem', 'item')
323324
->innerJoin('o.compositeLabel', 'label')
324325
->leftJoin('o.foo', 'foo', 'WITH', 'o.bar = item.foo')
326+
->leftJoin(DummyCar::class, 'car', 'WITH', 'car.id = o.car')
325327
->where('item.field1 = :foo')
326328
->setParameter('foo', 1);
327329

@@ -331,6 +333,7 @@ public function testFetchEagerWithNoForceEager()
331333
$queryNameGenerator->generateJoinAlias('o')->shouldBeCalled()->willReturn('o_2');
332334

333335
$queryNameGenerator->generateJoinAlias('foo')->shouldBeCalled()->willReturn('foo_2');
336+
$queryNameGenerator->generateJoinAlias(DummyCar::class)->shouldNotBeCalled();
334337

335338
$filterEagerLoadingExtension = new FilterEagerLoadingExtension($resourceMetadataFactoryProphecy->reveal(), false);
336339
$filterEagerLoadingExtension->applyToCollection($qb, $queryNameGenerator->reveal(), CompositeRelation::class, 'get');
@@ -341,6 +344,7 @@ public function testFetchEagerWithNoForceEager()
341344
INNER JOIN o.compositeItem item
342345
INNER JOIN o.compositeLabel label
343346
LEFT JOIN o.foo foo WITH o.bar = item.foo
347+
LEFT JOIN ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyCar car WITH car.id = o.car
344348
WHERE o.item IN(
345349
SELECT IDENTITY(o_2.item) FROM ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\CompositeRelation o_2
346350
INNER JOIN o_2.compositeItem item_2

0 commit comments

Comments
 (0)