fix:回退count查询
This commit is contained in:
parent
3b4e5e7833
commit
36ba5041b8
@ -252,11 +252,8 @@ func SqlQuery(tx *gorm.DB, sql string, list interface{}, q *PaginationQuery, par
|
||||
// 记录条数
|
||||
if needDoCount(q) {
|
||||
var total int64
|
||||
// 使用安全的 COUNT 查询
|
||||
countSQL := replaceSelectAndRemoveGroupBy(sql2)
|
||||
if err := tx.Raw(countSQL, params...).Take(&total).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
//tx = tx.Count(&total)
|
||||
tx.Raw("SELECT COUNT(*) as total FROM ("+sql2+") aaaa", params...).Take(&total)
|
||||
q.Total = int(total)
|
||||
if total == 0 { // 如果查了记录条数并且是0, 就不需要查记录和汇总了
|
||||
return
|
||||
|
||||
Loading…
Reference in New Issue
Block a user