Skip to content

Commit bce0103

Browse files
authored
Merge pull request api-platform#1311 from soyuka/fix/1310
fix api-platform#1310 join condition aliases in FilterEagerLoadingExtension
2 parents e0c8465 + 5e766fd commit bce0103

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private function getQueryBuilderWithNewAliases(QueryBuilder $queryBuilder, Query
118118
$aliases[] = "{$joinPart->getAlias()}.";
119119
$alias = $queryNameGenerator->generateJoinAlias($joinPart->getAlias());
120120
$replacements[] = "$alias.";
121-
$join = new Join($joinPart->getJoinType(), str_replace($aliases, $replacements, $joinPart->getJoin()), $alias, $joinPart->getConditionType(), $joinPart->getCondition(), $joinPart->getIndexBy());
121+
$join = new Join($joinPart->getJoinType(), str_replace($aliases, $replacements, $joinPart->getJoin()), $alias, $joinPart->getConditionType(), str_replace($aliases, $replacements, $joinPart->getCondition()), $joinPart->getIndexBy());
122122

123123
$queryBuilderClone->add('join', [$join], true);
124124
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ public function testFetchEagerWithNoForceEager()
315315
->from(CompositeRelation::class, 'o')
316316
->innerJoin('o.compositeItem', 'item')
317317
->innerJoin('o.compositeLabel', 'label')
318+
->leftJoin('o.foo', 'foo', 'WITH', 'o.bar = item.foo')
318319
->where('item.field1 = :foo')
319320
->setParameter('foo', 1);
320321

@@ -323,6 +324,8 @@ public function testFetchEagerWithNoForceEager()
323324
$queryNameGenerator->generateJoinAlias('label')->shouldBeCalled()->willReturn('label_2');
324325
$queryNameGenerator->generateJoinAlias('o')->shouldBeCalled()->willReturn('o_2');
325326

327+
$queryNameGenerator->generateJoinAlias('foo')->shouldBeCalled()->willReturn('foo_2');
328+
326329
$filterEagerLoadingExtension = new FilterEagerLoadingExtension($resourceMetadataFactoryProphecy->reveal(), false);
327330
$filterEagerLoadingExtension->applyToCollection($qb, $queryNameGenerator->reveal(), CompositeRelation::class, 'get');
328331

@@ -331,15 +334,18 @@ public function testFetchEagerWithNoForceEager()
331334
FROM ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\CompositeRelation o
332335
INNER JOIN o.compositeItem item
333336
INNER JOIN o.compositeLabel label
337+
LEFT JOIN o.foo foo WITH o.bar = item.foo
334338
WHERE o.item IN(
335339
SELECT IDENTITY(o_2.item) FROM ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\CompositeRelation o_2
336340
INNER JOIN o_2.compositeItem item_2
337341
INNER JOIN o_2.compositeLabel label_2
342+
LEFT JOIN o_2.foo foo_2 WITH o_2.bar = item_2.foo
338343
WHERE item_2.field1 = :foo
339344
) AND o.label IN(
340345
SELECT IDENTITY(o_2.label) FROM ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\CompositeRelation o_2
341346
INNER JOIN o_2.compositeItem item_2
342347
INNER JOIN o_2.compositeLabel label_2
348+
LEFT JOIN o_2.foo foo_2 WITH o_2.bar = item_2.foo
343349
WHERE item_2.field1 = :foo
344350
)
345351
SQL;

0 commit comments

Comments
 (0)