Fixing issue found by test cases, column names containing table names.
This commit is contained in:
parent
0c51a60e9a
commit
a2df1deb85
|
@ -55,10 +55,11 @@ export default class AliasTables {
|
|||
|
||||
aliasField(field: string) {
|
||||
const tableNames = this.tableNames
|
||||
const foundTable = tableNames.find(name => field.includes(name))
|
||||
const possibleTableName = field.substring(0, field.lastIndexOf("."))
|
||||
const foundTable = tableNames.find(name => possibleTableName.includes(name))
|
||||
if (foundTable) {
|
||||
const aliasedTable = this.getAlias(foundTable)
|
||||
return field.replace(foundTable, aliasedTable)
|
||||
field = field.replace(foundTable, aliasedTable)
|
||||
}
|
||||
return field
|
||||
}
|
||||
|
|
|
@ -189,5 +189,12 @@ describe("Captures of real examples", () => {
|
|||
const aliased = aliasing.aliasField("`hello.world`.`field`")
|
||||
expect(aliased).toEqual("`a`.`field`")
|
||||
})
|
||||
|
||||
it("should handle if a table name is used in a column", () => {
|
||||
const tableNames = ["hello", "world"]
|
||||
const aliasing = new AliasTables(tableNames)
|
||||
const aliased = aliasing.aliasField(`"hello"."world_relation"`)
|
||||
expect(aliased).toEqual(`"a"."world_relation"`)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue