Skip to content

Commit 9730895

Browse files
committed
Fix ambiguous column references in spatial queries
Resolves an issue where column references were becoming ambiguous in complex joins involving geometry columns. This change modifies the path generation to explicitly qualify columns with their schema or table alias, replacing the previous approach that created unqualified column names. Specifically, we now prepend the schema or alias name with a dot separator before the column path, ensuring proper SQL column qualification. This prevents errors like "column reference is ambiguous" when using spatial functions on tables with similar column names in multi-table joins. Signed-off-by: bwdmr <[email protected]>
1 parent 14a5a68 commit 9730895

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Sources/FluentPostGIS/Queries/QueryBuilder+Helpers.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ extension QueryBuilder {
1515
static func path<M, F>(_ field: KeyPath<M, F>) -> any SQLExpression
1616
where M: Schema, F: QueryableProperty, F.Model == M
1717
{
18-
let path = M.path(for: field).map(\.description).joined(separator: "_")
19-
return SQLColumn(path)
18+
let schema = SQLIdentifier(M.schemaOrAlias)
19+
let path = SQLIdentifier(M.path(for: field).map(\.description).joined(separator: "_"))
20+
return SQLColumn(path, table: schema)
2021
}
2122
}
2223

0 commit comments

Comments
 (0)