From 5e181ea44c6426f8f205b71d05b5e215fb5f9e05 Mon Sep 17 00:00:00 2001 From: Michael Bromley Date: Mon, 12 Apr 2021 10:04:14 +0200 Subject: [PATCH] fix(core): Join eager relations on OrderService.findOne method --- packages/core/src/service/services/order.service.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/core/src/service/services/order.service.ts b/packages/core/src/service/services/order.service.ts index a5cd1fa430..48072dfab0 100644 --- a/packages/core/src/service/services/order.service.ts +++ b/packages/core/src/service/services/order.service.ts @@ -37,6 +37,7 @@ import { import { ID, PaginatedList } from '@vendure/common/lib/shared-types'; import { summate } from '@vendure/common/lib/shared-utils'; import { unique } from '@vendure/common/lib/unique'; +import { FindOptionsUtils } from 'typeorm/find-options/FindOptionsUtils'; import { RequestContext } from '../../api/common/request-context'; import { ErrorResultUnion, isGraphQlErrorResult } from '../../common/error/error-result'; @@ -183,7 +184,7 @@ export class OrderService { } async findOne(ctx: RequestContext, orderId: ID): Promise { - const order = await this.connection + const qb = this.connection .getRepository(ctx, Order) .createQueryBuilder('order') .leftJoin('order.channels', 'channel') @@ -203,8 +204,12 @@ export class OrderService { .where('order.id = :orderId', { orderId }) .andWhere('channel.id = :channelId', { channelId: ctx.channelId }) .addOrderBy('lines.createdAt', 'ASC') - .addOrderBy('items.createdAt', 'ASC') - .getOne(); + .addOrderBy('items.createdAt', 'ASC'); + + // tslint:disable-next-line:no-non-null-assertion + FindOptionsUtils.joinEagerRelations(qb, qb.alias, qb.expressionMap.mainAlias!.metadata); + + const order = await qb.getOne(); if (order) { for (const line of order.lines) { line.productVariant = translateDeep(