Skip to content

Commit

Permalink
fix: auto add alias for order column added via Column() method if the…
Browse files Browse the repository at this point in the history
… column in the table FieldMap
  • Loading branch information
ilxqx committed Dec 11, 2023
1 parent 8a43835 commit 50c70de
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions query_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -781,11 +781,22 @@ func (q *SelectQuery) appendOrder(fmter schema.Formatter, b []byte) (_ []byte, e
if len(q.order) > 0 {
b = append(b, " ORDER BY "...)

for i, f := range q.order {
for i, ord := range q.order {
if i > 0 {
b = append(b, ", "...)
}
b, err = f.AppendQuery(fmter, b)

// Auto add alias for order column added via Column() method if the column in the table FieldMap
if ord.Args == nil && q.table != nil {
if field, ok := q.table.FieldMap[ord.Query]; ok {
b = append(b, q.table.SQLAlias...)
b = append(b, '.')
b = append(b, field.SQLName...)
continue
}
}

b, err = ord.AppendQuery(fmter, b)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 50c70de

Please sign in to comment.