From 258afd1bbdbedc1fd0ed7c495d04c82ee5ae1520 Mon Sep 17 00:00:00 2001 From: Jonas Osburg Date: Thu, 18 Jul 2024 11:31:13 +0200 Subject: [PATCH] fix(core): Truncate db aliases if necessary Fixes #2899 --- .../service/helpers/utils/tree-relations-qb-joiner.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/core/src/service/helpers/utils/tree-relations-qb-joiner.ts b/packages/core/src/service/helpers/utils/tree-relations-qb-joiner.ts index 0d372b7e12..db4e6dbb07 100644 --- a/packages/core/src/service/helpers/utils/tree-relations-qb-joiner.ts +++ b/packages/core/src/service/helpers/utils/tree-relations-qb-joiner.ts @@ -1,6 +1,6 @@ import { EntityMetadata, FindOneOptions, SelectQueryBuilder } from 'typeorm'; import { EntityTarget } from 'typeorm/common/EntityTarget'; -import { FindOptionsRelationByString, FindOptionsRelations } from 'typeorm/find-options/FindOptionsRelations'; +import { DriverUtils } from 'typeorm/driver/DriverUtils'; import { findOptionsObjectToArray } from '../../../connection/find-options-object-to-array'; import { VendureEntity } from '../../../entity'; @@ -108,7 +108,12 @@ export function joinTreeRelationsDynamically( if (relationMetadata.isEager) { joinConnector = '__'; } - const nextAlias = `${currentAlias}${joinConnector}${part.replace(/\./g, '_')}`; + const nextAlias = DriverUtils.buildAlias( + qb.connection.driver, + { shorten: false }, + currentAlias, + part.replace(/\./g, '_'), + ); const nextPath = parts.join('.'); const fullPath = [...(parentPath || []), part].join('.'); if (!qb.expressionMap.joinAttributes.some(ja => ja.alias.name === nextAlias)) {