@@ -264,19 +264,18 @@ export class RelationQueryBuilder<Entity, Relation> {
264
264
} ) . join ( ' AND ' ) ;
265
265
266
266
const whereParams = { } ;
267
- const andSelect = [ ] ;
268
267
const whereCondition = primaryColumns . map ( ( column ) => {
269
268
const paramName = this . getParamName ( aliasName ) ;
270
269
271
270
whereParams [ paramName ] = entities . map ( ( entity ) => column . getEntityValue ( entity ) ) ;
272
271
273
272
// Also select the columns, so we can use them to map later
274
- andSelect . push ( `${ aliasName } .${ column . propertyPath } ` ) ;
273
+ qb . addSelect ( `${ aliasName } .${ column . propertyPath } ` )
274
+
275
275
return `${ aliasName } .${ column . propertyPath } IN (:...${ paramName } )` ;
276
276
} ) . join ( ' AND ' ) ;
277
277
278
278
return qb . leftJoin ( relation . entityMetadata . target as Class < unknown > , aliasName , joinCondition )
279
- . addSelect ( andSelect )
280
279
. andWhere ( whereCondition , whereParams ) ;
281
280
} ,
282
281
@@ -394,14 +393,14 @@ export class RelationQueryBuilder<Entity, Relation> {
394
393
395
394
batchSelect : ( qb , entities : Entity [ ] ) => {
396
395
const params = { } ;
397
- const andSelect = [ ] ;
398
396
399
397
const sql = relation . joinColumns . map ( ( column ) => {
400
398
const paramName = this . getParamName ( column . propertyName ) ;
401
399
params [ paramName ] = entities . map ( ( entity ) => column . referencedColumn ! . getEntityValue ( entity ) ) ;
402
400
403
401
// We also want to select the field, so we can map them back in the mapper
404
- andSelect . push ( `${ joinAlias } .${ column . propertyName } AS ${ joinAlias } _${ column . propertyName } ` ) ;
402
+ qb . addSelect ( `${ joinAlias } .${ column . propertyName } ` , `${ joinAlias } _${ column . propertyName } ` )
403
+
405
404
return `${ joinAlias } .${ column . propertyName } IN (:...${ paramName } )` ;
406
405
} ) . join ( ' AND ' ) ;
407
406
@@ -411,7 +410,6 @@ export class RelationQueryBuilder<Entity, Relation> {
411
410
412
411
return qb . innerJoin ( join . target , join . alias , conditions . join ( ' AND ' ) ) ;
413
412
} , qb )
414
- . addSelect ( andSelect )
415
413
. andWhere ( sql , params ) ;
416
414
} ,
417
415
@@ -469,10 +467,9 @@ export class RelationQueryBuilder<Entity, Relation> {
469
467
// First filter the raw relations with the PK of the entity, then filter the relations
470
468
// with the PK of the raw relation
471
469
return lodashFilter ( rawRelations , rawFilter ) . reduce ( ( entityRelations , rawRelation ) => {
472
- const filter = relation . inverseRelation . joinColumns . reduce ( ( columns , column ) => ( {
470
+ const filter = this . getRelationPrimaryKeysPropertyNameAndColumnsName ( ) . reduce ( ( columns , column ) => ( {
473
471
...columns ,
474
-
475
- [ column . referencedColumn . propertyName ] : rawRelation [ `${ joinAlias } _${ column . propertyName } ` ]
472
+ [ column . propertyName ] : rawRelation [ column . columnName ]
476
473
} ) , { } as Partial < Entity > ) ;
477
474
478
475
return entityRelations . concat ( lodashFilter ( relations , filter ) as any ) ;
@@ -481,14 +478,14 @@ export class RelationQueryBuilder<Entity, Relation> {
481
478
482
479
batchSelect : ( qb , entities : Entity [ ] ) => {
483
480
const params = { } ;
484
- const andSelect = [ ] ;
485
481
486
482
const sql = relation . inverseRelation ! . inverseJoinColumns . map ( ( column ) => {
487
483
const paramName = this . getParamName ( column . propertyName ) ;
488
484
params [ paramName ] = entities . map ( ( entity ) => column . referencedColumn ! . getEntityValue ( entity ) ) ;
489
485
490
486
// We also want to select the field, so we can map them back in the mapper
491
- andSelect . push ( `${ joinAlias } .${ column . propertyName } AS ${ joinAlias } _${ column . propertyName } ` ) ;
487
+ qb . addSelect ( `${ joinAlias } .${ column . propertyName } ` , `${ joinAlias } _${ column . propertyName } ` )
488
+
492
489
return `${ joinAlias } .${ column . propertyName } IN (:...${ paramName } )` ;
493
490
} ) . join ( ' AND ' ) ;
494
491
@@ -498,7 +495,6 @@ export class RelationQueryBuilder<Entity, Relation> {
498
495
499
496
return qb . innerJoin ( join . target , join . alias , conditions . join ( ' AND ' ) ) ;
500
497
} , qb )
501
- . addSelect ( andSelect )
502
498
. andWhere ( sql , params ) ;
503
499
} ,
504
500
0 commit comments