Skip to content

Commit

Permalink
Merge branch 'master' of github.com:uptrace/bun
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Sep 9, 2021
2 parents 8c95378 + 36e9451 commit 705a2fe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions internal/dbtest/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ func testSelectScan(t *testing.T, db *bun.DB) {
func testSelectCount(t *testing.T, db *bun.DB) {
if !db.Dialect().Features().Has(feature.CTE) {
t.Skip()
return
}

values := db.NewValues(&[]map[string]interface{}{
Expand All @@ -273,12 +274,19 @@ func testSelectCount(t *testing.T, db *bun.DB) {
{"num": 3},
})

count, err := db.NewSelect().
q := db.NewSelect().
With("t", values).
Column("t.num").
TableExpr("t").
OrderExpr("t.num DESC").
Limit(1).
Count(ctx)
Limit(1)

var num int
err := q.Scan(ctx, &num)
require.NoError(t, err)
require.Equal(t, 3, num)

count, err := q.Count(ctx)
require.NoError(t, err)
require.Equal(t, 3, count)
}
Expand Down
2 changes: 1 addition & 1 deletion query_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ func (q *SelectQuery) appendColumns(fmter schema.Formatter, b []byte) (_ []byte,
b = append(b, ", "...)
}

if col.Args == nil {
if col.Args == nil && q.table != nil {
if field, ok := q.table.FieldMap[col.Query]; ok {
b = append(b, q.table.SQLAlias...)
b = append(b, '.')
Expand Down

0 comments on commit 705a2fe

Please sign in to comment.