From ae5bda7deb58e66765eded4bbbd16827e37f8164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=BE=99?= Date: Sun, 28 Nov 2021 17:32:47 +0800 Subject: [PATCH] fix: count() when use `group by` and only find one record --- finisher_api.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/finisher_api.go b/finisher_api.go index 78f764b8..aac3693a 100644 --- a/finisher_api.go +++ b/finisher_api.go @@ -419,11 +419,8 @@ func (db *DB) Count(count *int64) (tx *DB) { tx.Statement.Dest = count tx = tx.callbacks.Query().Execute(tx) - if tx.RowsAffected != 1 { - *count = tx.RowsAffected - } - if _, ok := db.Statement.Clauses["GROUP BY"]; ok && tx.RowsAffected == 1 { + if _, ok := db.Statement.Clauses["GROUP BY"]; (ok && tx.RowsAffected == 1) || tx.RowsAffected != 1 { *count = tx.RowsAffected }