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) {
|
if needDoCount(q) {
|
||||||
var total int64
|
var total int64
|
||||||
// 使用安全的 COUNT 查询
|
//tx = tx.Count(&total)
|
||||||
countSQL := replaceSelectAndRemoveGroupBy(sql2)
|
tx.Raw("SELECT COUNT(*) as total FROM ("+sql2+") aaaa", params...).Take(&total)
|
||||||
if err := tx.Raw(countSQL, params...).Take(&total).Error; err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
q.Total = int(total)
|
q.Total = int(total)
|
||||||
if total == 0 { // 如果查了记录条数并且是0, 就不需要查记录和汇总了
|
if total == 0 { // 如果查了记录条数并且是0, 就不需要查记录和汇总了
|
||||||
return
|
return
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user