Merge 9532a32c2a263511459c30494fbaa6564547a044 into 4e34a6d21b63e9a9b701a70be9759e5539bf26e9

This commit is contained in:
Mohamed Feddad 2025-08-21 23:26:23 +04:00 committed by GitHub
commit 2d7da50b49
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -458,6 +458,10 @@ func (db *DB) Count(count *int64) (tx *DB) {
defer delete(tx.Statement.Clauses, "SELECT")
}
if len(tx.Statement.scopes) > 0 {
tx.Statement.executeScopes()
}
if len(tx.Statement.Selects) == 0 {
tx.Statement.AddClause(clause.Select{Expression: clause.Expr{SQL: "count(*)"}})
} else if !strings.HasPrefix(strings.TrimSpace(strings.ToLower(tx.Statement.Selects[0])), "count(") {