From 83530ec65950f0731b895ca7ee8e89b1a29c7aa8 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Tue, 13 Jul 2021 21:17:43 +0800 Subject: [PATCH] Fix delete order by clause when counting, close #4478 --- finisher_api.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/finisher_api.go b/finisher_api.go index 51f394b4..537c955a 100644 --- a/finisher_api.go +++ b/finisher_api.go @@ -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 }() } }