fix: add _rel
suffix to relationship columns to avoid duplicate columns (#649)
This commit is contained in:
parent
34dff5ef09
commit
d328e343a4
@ -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}`
|
||||
|
@ -46,7 +46,7 @@ describe('paginate', () => {
|
||||
database: ':memory:',
|
||||
}),
|
||||
synchronize: true,
|
||||
logging: false,
|
||||
logging: ['error'],
|
||||
entities: [CatEntity, CatToyEntity, CatHomeEntity, CatHomePillowEntity],
|
||||
})
|
||||
await dataSource.initialize()
|
||||
|
@ -126,7 +126,10 @@ export async function paginate<T extends ObjectLiteral>(
|
||||
// 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<T extends ObjectLiteral>(
|
||||
|
||||
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`
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user