Skip to content

Commit

Permalink
feat(core): Fix for un-joined relations or joined with wrong alias
Browse files Browse the repository at this point in the history
  • Loading branch information
monrostar committed Mar 3, 2024
1 parent 32e0df7 commit f9f5260
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ export class ListQueryBuilder implements OnApplicationBootstrap {
skip,
where: extendedOptions.where || {},
relationLoadStrategy: extendedOptions?.relationLoadStrategy || 'query',
loadEagerRelations: true,

This comment has been minimized.

Copy link
@monrostar

monrostar Mar 3, 2024

Author Contributor

this is wrong, we don't need to use it here. Not nessesary

});

// join the tables required by calculated columns
Expand All @@ -307,22 +308,16 @@ export class ListQueryBuilder implements OnApplicationBootstrap {
}
const customFieldsForType = this.configService.customFields[entity.name as keyof CustomFields];
const sortParams = Object.assign({}, options.sort, extendedOptions.orderBy);
this.applyTranslationConditions(qb, entity, sortParams, extendedOptions.ctx, alias);
this.applyTranslationConditions(qb, entity, sortParams, extendedOptions.ctx);
const sort = parseSortParams(
rawConnection,
qb.connection,
entity,
sortParams,
customPropertyMap,
entityAlias,
qb.alias,
customFieldsForType,
);
const filter = parseFilterParams(
rawConnection,
entity,
options.filter,
customPropertyMap,
entityAlias,
);
const filter = parseFilterParams(qb.connection, entity, options.filter, customPropertyMap, qb.alias);

if (filter.length) {
const filterOperator = options.filterOperator ?? LogicalOperator.AND;
Expand Down Expand Up @@ -537,16 +532,11 @@ export class ListQueryBuilder implements OnApplicationBootstrap {
entity: Type<T>,
sortParams: NullOptionals<SortParameter<T>> & FindOneOptions<T>['order'],
ctx?: RequestContext,
entityAlias?: string,
) {
const languageCode = ctx?.languageCode || this.configService.defaultLanguageCode;

const {
columns,
translationColumns,
alias: defaultAlias,
} = getColumnMetadata(this.connection.rawConnection, entity);
const alias = entityAlias ?? defaultAlias;
const { translationColumns } = getColumnMetadata(qb.connection, entity);
const alias = qb.alias;

const sortKeys = Object.keys(sortParams);
let sortingOnTranslatableKey = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Type } from '@vendure/common/lib/shared-types';
import { unique } from '@vendure/common/lib/unique';
import { Connection, OrderByCondition } from 'typeorm';
import { OrderByCondition } from 'typeorm';
import { DataSource } from 'typeorm/data-source/DataSource';
import { ColumnMetadata } from 'typeorm/metadata/ColumnMetadata';

import { UserInputError } from '../../../common/error/errors';
Expand All @@ -22,7 +23,7 @@ import { getCalculatedColumns } from './get-calculated-columns';
* @param customFields
*/
export function parseSortParams<T extends VendureEntity>(
connection: Connection,
connection: DataSource,
entity: Type<T>,
sortParams?: NullOptionals<SortParameter<T>> | null,
customPropertyMap?: { [name: string]: string },
Expand Down

0 comments on commit f9f5260

Please sign in to comment.