@@ -211,6 +211,47 @@ public function testApplyCollectionWithManualJoin()
211
211
$ this ->assertEquals ($ this ->toDQLString ($ expected ), $ qb ->getDQL ());
212
212
}
213
213
214
+ public function testApplyCollectionCorrectlyReplacesJoinCondition ()
215
+ {
216
+ $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
217
+ $ resourceMetadataFactoryProphecy ->create (DummyCar::class)->willReturn (new ResourceMetadata (DummyCar::class));
218
+
219
+ $ resourceNameCollectionFactoryProphecy = $ this ->prophesize (ResourceNameCollectionFactoryInterface::class);
220
+ $ resourceNameCollectionFactoryProphecy ->create ()->willReturn (new ResourceNameCollection ([DummyTravel::class]));
221
+
222
+ $ em = $ this ->prophesize (EntityManager::class);
223
+ $ em ->getExpressionBuilder ()->shouldBeCalled ()->willReturn (new Expr ());
224
+ $ em ->getClassMetadata (DummyCar::class)->shouldBeCalled ()->willReturn (new ClassMetadataInfo (DummyCar::class));
225
+
226
+ $ qb = new QueryBuilder ($ em ->reveal ());
227
+
228
+ $ qb ->select ('o ' )
229
+ ->from (DummyCar::class, 'o ' )
230
+ ->leftJoin ('o.colors ' , 'colors ' , 'ON ' , 'o.id = colors.car AND colors.id IN (1,2,3) ' )
231
+ ->where ('o.colors = :foo ' )
232
+ ->setParameter ('foo ' , 1 );
233
+
234
+ $ queryNameGenerator = $ this ->prophesize (QueryNameGeneratorInterface::class);
235
+ $ queryNameGenerator ->generateJoinAlias ('colors ' )->shouldBeCalled ()->willReturn ('colors_2 ' );
236
+ $ queryNameGenerator ->generateJoinAlias ('o ' )->shouldBeCalled ()->willReturn ('o_2 ' );
237
+
238
+ $ filterEagerLoadingExtension = new FilterEagerLoadingExtension ($ resourceMetadataFactoryProphecy ->reveal (), true , new ResourceClassResolver ($ resourceNameCollectionFactoryProphecy ->reveal ()));
239
+ $ filterEagerLoadingExtension ->applyToCollection ($ qb , $ queryNameGenerator ->reveal (), DummyCar::class, 'get ' );
240
+
241
+ $ expected = <<<'SQL'
242
+ SELECT o
243
+ FROM ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyCar o
244
+ LEFT JOIN o.colors colors ON o.id = colors.car AND colors.id IN (1,2,3)
245
+ WHERE o IN(
246
+ SELECT o_2 FROM ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyCar o_2
247
+ LEFT JOIN o_2.colors colors_2 ON o_2.id = colors_2.car AND colors_2.id IN (1,2,3)
248
+ WHERE o_2.colors = :foo
249
+ )
250
+ SQL;
251
+
252
+ $ this ->assertEquals ($ this ->toDQLString ($ expected ), $ qb ->getDQL ());
253
+ }
254
+
214
255
/**
215
256
* https://github.com/api-platform/core/issues/1021.
216
257
*/
0 commit comments