fix: count with group (#6157)
This commit is contained in:
parent
cc2d46e5be
commit
0c51d655f3
@ -491,7 +491,7 @@ func (db *DB) Count(count *int64) (tx *DB) {
|
||||
tx.Statement.Dest = count
|
||||
tx = tx.callbacks.Query().Execute(tx)
|
||||
|
||||
if tx.RowsAffected != 1 {
|
||||
if _, ok := db.Statement.Clauses["GROUP BY"]; ok || tx.RowsAffected != 1 {
|
||||
*count = tx.RowsAffected
|
||||
}
|
||||
|
||||
|
@ -141,8 +141,8 @@ func TestCount(t *testing.T) {
|
||||
}
|
||||
DB.Create(sameUsers)
|
||||
|
||||
if err := DB.Model(&User{}).Where("name = ?", "count-4").Group("name").Count(&count11).Error; err != nil || count11 != int64(len(sameUsers)) {
|
||||
t.Fatalf("Count should be 3, but got count: %v err %v", count11, err)
|
||||
if err := DB.Model(&User{}).Where("name = ?", "count-4").Group("name").Count(&count11).Error; err != nil || count11 != 1 {
|
||||
t.Fatalf("Count should be 1, but got count: %v err %v", count11, err)
|
||||
}
|
||||
|
||||
var count12 int64
|
||||
|
Loading…
x
Reference in New Issue
Block a user