fix: count() when use group by and only find one record

This commit is contained in:
李龙 2021-11-28 17:32:47 +08:00
parent b90f112239
commit ae5bda7deb

View File

@ -419,11 +419,8 @@ func (db *DB) Count(count *int64) (tx *DB) {
tx.Statement.Dest = count tx.Statement.Dest = count
tx = tx.callbacks.Query().Execute(tx) 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 *count = tx.RowsAffected
} }