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 {
|
): string {
|
||||||
if (isRelation) {
|
if (isRelation) {
|
||||||
if (isVirtualProperty && query) {
|
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) {
|
} 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 {
|
} else {
|
||||||
return `${alias}_${properties.propertyPath}.${properties.propertyName}`
|
return `${alias}_${properties.propertyPath}_rel.${properties.propertyName}`
|
||||||
}
|
}
|
||||||
} else if (isVirtualProperty) {
|
} else if (isVirtualProperty) {
|
||||||
return query ? `(${query(`${alias}`)})` : `${alias}_${properties.propertyName}`
|
return query ? `(${query(`${alias}`)})` : `${alias}_${properties.propertyName}`
|
||||||
|
@ -46,7 +46,7 @@ describe('paginate', () => {
|
|||||||
database: ':memory:',
|
database: ':memory:',
|
||||||
}),
|
}),
|
||||||
synchronize: true,
|
synchronize: true,
|
||||||
logging: false,
|
logging: ['error'],
|
||||||
entities: [CatEntity, CatToyEntity, CatHomeEntity, CatHomePillowEntity],
|
entities: [CatEntity, CatToyEntity, CatHomeEntity, CatHomePillowEntity],
|
||||||
})
|
})
|
||||||
await dataSource.initialize()
|
await dataSource.initialize()
|
||||||
|
@ -126,7 +126,10 @@ export async function paginate<T extends ObjectLiteral>(
|
|||||||
// relations: ["relation"]
|
// relations: ["relation"]
|
||||||
if (Array.isArray(config.relations)) {
|
if (Array.isArray(config.relations)) {
|
||||||
config.relations.forEach((relation) => {
|
config.relations.forEach((relation) => {
|
||||||
queryBuilder.leftJoinAndSelect(`${queryBuilder.alias}.${relation}`, `${queryBuilder.alias}_${relation}`)
|
queryBuilder.leftJoinAndSelect(
|
||||||
|
`${queryBuilder.alias}.${relation}`,
|
||||||
|
`${queryBuilder.alias}_${relation}_rel`
|
||||||
|
)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
// relations: {relation:true}
|
// relations: {relation:true}
|
||||||
@ -141,11 +144,15 @@ export async function paginate<T extends ObjectLiteral>(
|
|||||||
|
|
||||||
queryBuilder.leftJoinAndSelect(
|
queryBuilder.leftJoinAndSelect(
|
||||||
`${alias ?? prefix}.${relationName}`,
|
`${alias ?? prefix}.${relationName}`,
|
||||||
`${alias ?? prefix}_${relationName}`
|
`${alias ?? prefix}_${relationName}_rel`
|
||||||
)
|
)
|
||||||
|
|
||||||
if (typeof relationSchema === 'object') {
|
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