Skip to content

Commit

Permalink
Merge pull request #2016 from partageit/2.2
Browse files Browse the repository at this point in the history
FilterEagerLoadingExtension accepts joins with class name as join value
  • Loading branch information
soyuka committed Jun 11, 2018
2 parents 33fe2d0 + 0ece408 commit 9790b8d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Expand Up @@ -135,6 +135,9 @@ private function getQueryBuilderWithNewAliases(QueryBuilder $queryBuilder, Query
/** @var Join $joinPart */
$joinString = str_replace($aliases, $replacements, $joinPart->getJoin());
$pos = strpos($joinString, '.');
if (false === $pos) {
continue;
}
$alias = substr($joinString, 0, $pos);
$association = substr($joinString, $pos + 1);
$condition = str_replace($aliases, $replacements, $joinPart->getCondition());
Expand Down
Expand Up @@ -302,6 +302,7 @@ public function testFetchEagerWithNoForceEager()
{
$resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataFactoryInterface::class);
$resourceMetadataFactoryProphecy->create(CompositeRelation::class)->willReturn(new ResourceMetadata(CompositeRelation::class));
$resourceMetadataFactoryProphecy->create(DummyCar::class)->willReturn(new ResourceMetadata(DummyCar::class));

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

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

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

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

0 comments on commit 9790b8d

Please sign in to comment.