Fix delete order by clause when counting, close #4478

This commit is contained in:
Jinzhu 2021-07-13 21:17:43 +08:00
parent 52b72d7ef2
commit 83530ec659
1 changed files with 3 additions and 3 deletions

View File

@ -376,7 +376,7 @@ func (db *DB) Count(count *int64) (tx *DB) {
if selectClause, ok := db.Statement.Clauses["SELECT"]; ok {
defer func() {
db.Statement.Clauses["SELECT"] = selectClause
tx.Statement.Clauses["SELECT"] = selectClause
}()
} else {
defer delete(tx.Statement.Clauses, "SELECT")
@ -410,9 +410,9 @@ func (db *DB) Count(count *int64) (tx *DB) {
if orderByClause, ok := db.Statement.Clauses["ORDER BY"]; ok {
if _, ok := db.Statement.Clauses["GROUP BY"]; !ok {
delete(db.Statement.Clauses, "ORDER BY")
delete(tx.Statement.Clauses, "ORDER BY")
defer func() {
db.Statement.Clauses["ORDER BY"] = orderByClause
tx.Statement.Clauses["ORDER BY"] = orderByClause
}()
}
}