Skip to content

Commit

Permalink
fix(core): Fix findByIdsInChannel to take ids into account (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyratox authored Jun 8, 2020
1 parent f385d69 commit dd4bbc9
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ export function findByIdsInChannel<T extends ChannelAware | VendureEntity>(
findOptions?: FindManyOptions<T>,
eager = true,
) {
//the syntax described in https://github.com/typeorm/typeorm/issues/1239#issuecomment-366955628
//breaks if the array is empty
if(ids.length === 0){
return Promise.resolve([]);
}

const qb = connection.getRepository(entity).createQueryBuilder('product');
FindOptionsUtils.applyFindManyOptionsOrConditionsToQueryBuilder(qb, findOptions);
if (eager) {
Expand All @@ -24,6 +30,7 @@ export function findByIdsInChannel<T extends ChannelAware | VendureEntity>(
}
return qb
.leftJoin('product.channels', 'channel')
.andWhere("product.id IN (:...ids)", { ids })
.andWhere('channel.id = :channelId', { channelId })
.getMany();
}
Expand Down

0 comments on commit dd4bbc9

Please sign in to comment.