@@ -403,6 +403,7 @@ private function initColumnArrays()
403
403
$ this ->addSearchColumn ($ column , null , $ searchDql );
404
404
} elseif (true === $ this ->accessor ->getValue ($ column , 'selectColumn ' )) {
405
405
$ parts = explode ('. ' , $ dql );
406
+ $ withExpr = $ this ->accessor ->getValue ($ column , 'joinConditions ' );
406
407
407
408
while (\count ($ parts ) > 1 ) {
408
409
$ previousPart = $ currentPart ;
@@ -412,8 +413,14 @@ private function initColumnArrays()
412
413
$ currentAlias = ($ previousPart === $ this ->entityShortName ? '' : $ previousPart .'_ ' ).$ currentPart ;
413
414
$ currentAlias = $ this ->getSafeName ($ currentAlias );
414
415
415
- if (! \array_key_exists ($ previousAlias .'. ' .$ currentPart , $ this ->joins )) {
416
- $ this ->addJoin ($ previousAlias .'. ' .$ currentPart , $ currentAlias , $ this ->accessor ->getValue ($ column , 'joinType ' ));
416
+ $ columnTableName = $ previousAlias .'. ' .$ currentPart ;
417
+ if (!array_key_exists ($ columnTableName , $ this ->joins )) {
418
+ $ this ->addJoin ($ columnTableName , $ currentAlias , $ this ->accessor ->getValue ($ column , 'joinType ' ));
419
+ }
420
+ // for the last dql part join using WITH, if expression is given for column
421
+ if (count ($ parts ) === 1 && array_key_exists ($ columnTableName , $ this ->joins ) && null !== $ withExpr ) {
422
+ $ with = str_replace ($ currentPart . '. ' , $ currentAlias . '. ' , $ withExpr );
423
+ $ this ->addJoin ($ columnTableName , $ currentAlias , $ this ->accessor ->getValue ($ column , 'joinType ' ), $ with );
417
424
}
418
425
419
426
$ metadata = $ this ->setIdentifierFromAssociation ($ currentAlias , $ currentPart , $ metadata );
@@ -486,7 +493,11 @@ private function setSelectFrom(QueryBuilder $qb)
486
493
private function setJoins (QueryBuilder $ qb )
487
494
{
488
495
foreach ($ this ->joins as $ key => $ value ) {
489
- $ qb ->{$ value ['type ' ]}($ key , $ value ['alias ' ]);
496
+ if (\array_key_exists ('with ' , $ value ) && null !== $ value ['with ' ]) {
497
+ $ qb ->{$ value ['type ' ]}($ key , $ value ['alias ' ], Query \Expr \Join::WITH , $ value ['with ' ]);
498
+ } else {
499
+ $ qb ->{$ value ['type ' ]}($ key , $ value ['alias ' ]);
500
+ }
490
501
}
491
502
492
503
return $ this ;
@@ -714,14 +725,16 @@ private function addSearchOrderColumn($column, $columnTableName, $data)
714
725
* @param string $columnTableName
715
726
* @param string $alias
716
727
* @param string $type
728
+ * @param string $with
717
729
*
718
730
* @return $this
719
731
*/
720
- private function addJoin ($ columnTableName , $ alias , $ type )
732
+ private function addJoin ($ columnTableName , $ alias , $ type, $ with = null )
721
733
{
722
734
$ this ->joins [$ columnTableName ] = [
723
735
'alias ' => $ alias ,
724
736
'type ' => $ type ,
737
+ 'with ' => $ with ,
725
738
];
726
739
727
740
return $ this ;
0 commit comments