diff --git a/src/helper.ts b/src/helper.ts index 8e4c73b..20921b4 100644 --- a/src/helper.ts +++ b/src/helper.ts @@ -137,11 +137,16 @@ export function fixColumnAlias( ): string { if (isRelation) { if (isVirtualProperty && query) { - return `(${query(`${alias}_${properties.propertyPath}`)})` // () is needed to avoid parameter conflict + return `(${query(`${alias}_${properties.propertyPath}_rel`)})` // () is needed to avoid parameter conflict } else if ((isVirtualProperty && !query) || properties.isNested) { - return `${alias}_${properties.propertyPath}_${properties.propertyName}` + if (properties.propertyName.includes('.')) { + const [nestedRel, nestedCol] = properties.propertyName.split('.') + return `${alias}_${properties.propertyPath}_rel_${nestedRel}_rel.${nestedCol}` + } else { + return `${alias}_${properties.propertyPath}_rel_${properties.propertyName}` + } } else { - return `${alias}_${properties.propertyPath}.${properties.propertyName}` + return `${alias}_${properties.propertyPath}_rel.${properties.propertyName}` } } else if (isVirtualProperty) { return query ? `(${query(`${alias}`)})` : `${alias}_${properties.propertyName}` diff --git a/src/paginate.spec.ts b/src/paginate.spec.ts index 16278ad..ed01df4 100644 --- a/src/paginate.spec.ts +++ b/src/paginate.spec.ts @@ -46,7 +46,7 @@ describe('paginate', () => { database: ':memory:', }), synchronize: true, - logging: false, + logging: ['error'], entities: [CatEntity, CatToyEntity, CatHomeEntity, CatHomePillowEntity], }) await dataSource.initialize() diff --git a/src/paginate.ts b/src/paginate.ts index fc0e184..d1586c1 100644 --- a/src/paginate.ts +++ b/src/paginate.ts @@ -126,7 +126,10 @@ export async function paginate( // relations: ["relation"] if (Array.isArray(config.relations)) { config.relations.forEach((relation) => { - queryBuilder.leftJoinAndSelect(`${queryBuilder.alias}.${relation}`, `${queryBuilder.alias}_${relation}`) + queryBuilder.leftJoinAndSelect( + `${queryBuilder.alias}.${relation}`, + `${queryBuilder.alias}_${relation}_rel` + ) }) } else { // relations: {relation:true} @@ -141,11 +144,15 @@ export async function paginate( queryBuilder.leftJoinAndSelect( `${alias ?? prefix}.${relationName}`, - `${alias ?? prefix}_${relationName}` + `${alias ?? prefix}_${relationName}_rel` ) if (typeof relationSchema === 'object') { - createQueryBuilderRelations(relationName, relationSchema, `${alias ?? prefix}_${relationName}`) + createQueryBuilderRelations( + relationName, + relationSchema, + `${alias ?? prefix}_${relationName}_rel` + ) } }) }