Remove regex guess on counting query - replace with explicit set on Count() call to fix order by issues

This commit is contained in:
Jason Seriff 2016-01-25 14:28:02 -06:00
parent 9739cb853c
commit 3a13eade4e
1 changed files with 2 additions and 5 deletions

View File

@ -220,8 +220,6 @@ func (scope *Scope) whereSql() (sql string) {
return
}
var hasCountRegexp = regexp.MustCompile(`(?i)count\(.+\)`)
func (scope *Scope) selectSql() string {
if len(scope.Search.selects) == 0 {
if scope.Search.joins != "" {
@ -229,9 +227,7 @@ func (scope *Scope) selectSql() string {
}
return "*"
}
sql := scope.buildSelectQuery(scope.Search.selects)
scope.Search.countingQuery = (len(scope.Search.group) == 0) && hasCountRegexp.MatchString(sql)
return sql
return scope.buildSelectQuery(scope.Search.selects)
}
func (scope *Scope) orderSql() string {
@ -416,6 +412,7 @@ func (scope *Scope) pluck(column string, value interface{}) *Scope {
func (scope *Scope) count(value interface{}) *Scope {
scope.Search.Select("count(*)")
scope.Search.countingQuery = true
scope.Err(scope.row().Scan(value))
return scope
}