diff --git a/src/helper.ts b/src/helper.ts index 9aa0feb..6acba04 100644 --- a/src/helper.ts +++ b/src/helper.ts @@ -180,22 +180,11 @@ export function fixColumnAlias( ): string { if (isRelation) { if (isVirtualProperty && query) { - return `(${query(`${alias}_${properties.propertyPath}_rel`)})` // () is needed to avoid parameter conflict + return `(${query(`${alias}_${properties.propertyPath}`)})` // () is needed to avoid parameter conflict } else if ((isVirtualProperty && !query) || properties.isNested) { - if (properties.propertyName.includes('.')) { - const propertyPath = properties.propertyName.split('.') - const nestedRelations = propertyPath - .slice(0, -1) - .map((v) => `${v}_rel`) - .join('_') - const nestedCol = propertyPath[propertyPath.length - 1] - - return `${alias}_${properties.propertyPath}_rel_${nestedRelations}.${nestedCol}` - } else { - return `${alias}_${properties.propertyPath}_rel_${properties.propertyName}` - } + return `${alias}_${properties.propertyPath}_${properties.propertyName}` } else { - return `${alias}_${properties.propertyPath}_rel.${properties.propertyName}` + return `${alias}_${properties.propertyPath}.${properties.propertyName}` } } else if (isVirtualProperty) { return query ? `(${query(`${alias}`)})` : `${alias}_${properties.propertyName}` diff --git a/src/paginate.ts b/src/paginate.ts index 46f061e..722a487 100644 --- a/src/paginate.ts +++ b/src/paginate.ts @@ -155,11 +155,11 @@ function flattenWhereAndTransform( ? '' : `_${pathSplit .slice(0, -1) - .map((p) => p + '_rel') + .map((p) => p) .join('_')}` const tableName = pathSplit[pathSplit.length - 1] const tableAliasWithProperty = `${queryBuilder.alias}${fullPath}.${tableName}` - const joinTableAlias = `${queryBuilder.alias}${fullPath}_${tableName}_rel` + const joinTableAlias = `${queryBuilder.alias}${fullPath}_${tableName}` const baseTableAlias = allJoinedTables[joinTableAlias] @@ -229,11 +229,11 @@ export async function paginate( queryBuilder.leftJoinAndSelect( `${alias ?? prefix}.${relationName}`, - `${alias ?? prefix}_${relationName}_rel` + `${alias ?? prefix}_${relationName}` ) if (typeof relationSchema === 'object') { - createQueryBuilderRelations(relationName, relationSchema, `${alias ?? prefix}_${relationName}_rel`) + createQueryBuilderRelations(relationName, relationSchema, `${alias ?? prefix}_${relationName}`) } }) }