mirror of https://github.com/go-gorm/gorm.git
fix count() …
COUNT()函数逻辑有错误,本应该是在执行任何SQL的时候,都可以返回正确的行数。而现在复杂的SQL集合无法正确获取行数。
This commit is contained in:
parent
c3bb6aaa82
commit
56fffcb25b
7
scope.go
7
scope.go
|
@ -950,7 +950,12 @@ func (scope *Scope) pluck(column string, value interface{}) *Scope {
|
|||
|
||||
func (scope *Scope) count(value interface{}) *Scope {
|
||||
if query, ok := scope.Search.selects["query"]; !ok || !countingQueryRegexp.MatchString(fmt.Sprint(query)) {
|
||||
scope.Search.Select("count(*)")
|
||||
if len(scope.Search.group) != 0 {
|
||||
scope.Search.Select("count(*) FROM ( SELECT count(*) ")
|
||||
scope.Search.group += " ) AS count"
|
||||
} else {
|
||||
scope.Search.Select("count(*)")
|
||||
}
|
||||
}
|
||||
scope.Search.ignoreOrderQuery = true
|
||||
scope.Err(scope.row().Scan(value))
|
||||
|
|
Loading…
Reference in New Issue