Skip to content

Commit 3c0cf3a

Browse files
committed
fix: use table alias
1 parent 2e63fec commit 3c0cf3a

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

orm/query.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,10 @@ func (q *Query) ExcludeColumn(columns ...string) *Query {
363363
// AppendColumn appends column to the list of default columns if they weren't set,
364364
// while Column method overrides defaults
365365
func (q *Query) AppendColumn(columns ...string) *Query {
366+
t := q.tableModel.Table()
366367
if q.columns == nil {
367-
for _, f := range q.tableModel.Table().Fields {
368-
q.columns = append(q.columns, fieldAppender{f.SQLName})
368+
for _, f := range t.Fields {
369+
q.columns = append(q.columns, fieldAppender{fmt.Sprintf("%s.%s", t.Alias, f.SQLName)})
369370
}
370371
}
371372
return q.Column(columns...)
@@ -374,9 +375,10 @@ func (q *Query) AppendColumn(columns ...string) *Query {
374375
// AppendColumnExpr appends column expression to the list of default columns if they weren't set,
375376
// while ColumnExpr method overrides defaults
376377
func (q *Query) AppendColumnExpr(expr string, params ...interface{}) *Query {
378+
t := q.tableModel.Table()
377379
if q.columns == nil {
378-
for _, f := range q.tableModel.Table().Fields {
379-
q.columns = append(q.columns, fieldAppender{f.SQLName})
380+
for _, f := range t.Fields {
381+
q.columns = append(q.columns, fieldAppender{fmt.Sprintf("%s.%s", t.Alias, f.SQLName)})
380382
}
381383
}
382384
return q.ColumnExpr(expr, params...)

0 commit comments

Comments
 (0)