Skip to content

Commit

Permalink
fix(core): Fix error in joining list query relations
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Apr 3, 2024
1 parent 6588365 commit 33db45d
Showing 1 changed file with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import { ID, Type } from '@vendure/common/lib/shared-types';
import { unique } from '@vendure/common/lib/unique';
import {
Brackets,
EntityMetadata,
FindOneOptions,
FindOptionsWhere,
Repository,
SelectQueryBuilder,
WhereExpressionBuilder,
} from 'typeorm';
import { EntityTarget } from 'typeorm/common/EntityTarget';
import { BetterSqlite3Driver } from 'typeorm/driver/better-sqlite3/BetterSqlite3Driver';
import { SqljsDriver } from 'typeorm/driver/sqljs/SqljsDriver';

Expand All @@ -26,12 +24,12 @@ import {
import { ConfigService, CustomFields, Logger } from '../../../config';
import { TransactionalConnection } from '../../../connection';
import { VendureEntity } from '../../../entity';
import { joinTreeRelationsDynamically } from '../utils/tree-relations-qb-joiner';

import { getColumnMetadata, getEntityAlias } from './connection-utils';
import { getCalculatedColumns } from './get-calculated-columns';
import { parseFilterParams, WhereGroup } from './parse-filter-params';
import { parseSortParams } from './parse-sort-params';
import { joinTreeRelationsDynamically } from '../utils/tree-relations-qb-joiner';

/**
* @description
Expand Down Expand Up @@ -201,7 +199,10 @@ export type ExtendedListQueryOptions<T extends VendureEntity> = {
*/
@Injectable()
export class ListQueryBuilder implements OnApplicationBootstrap {
constructor(private connection: TransactionalConnection, private configService: ConfigService) {}
constructor(
private connection: TransactionalConnection,
private configService: ConfigService,
) {}

/** @internal */
onApplicationBootstrap(): any {
Expand Down Expand Up @@ -369,8 +370,8 @@ export class ListQueryBuilder implements OnApplicationBootstrap {
const takeLimit = ignoreQueryLimits
? Number.MAX_SAFE_INTEGER
: apiType === 'admin'
? adminListQueryLimit
: shopListQueryLimit;
? adminListQueryLimit
: shopListQueryLimit;
if (options.take && options.take > takeLimit) {
throw new UserInputError('error.list-query-limit-exceeded', { limit: takeLimit });
}
Expand Down Expand Up @@ -464,12 +465,7 @@ export class ListQueryBuilder implements OnApplicationBootstrap {
delete customPropertyMap[property];
return;
}
const alias = qb.connection.namingStrategy.joinTableName(
entityMetadata.tableName,
relationMetadata.propertyName,
'',
'',
);
const alias = `${entityMetadata.tableName}_${relationMetadata.propertyName}`;
if (!this.isRelationAlreadyJoined(qb, alias)) {
qb.leftJoinAndSelect(`${entityAlias}.${relationMetadata.propertyName}`, alias);
}
Expand Down

0 comments on commit 33db45d

Please sign in to comment.