Fixing issue found by test cases, column names containing table names.

This commit is contained in:
mike12345567 2024-02-28 11:08:35 +00:00
parent 0c51a60e9a
commit a2df1deb85
2 changed files with 10 additions and 2 deletions

View File

@ -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
}

View File

@ -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"`)
})
})
})