From 3a13eade4eadd9e9ef9aef6f2c0bbb9918e2e81d Mon Sep 17 00:00:00 2001 From: Jason Seriff Date: Mon, 25 Jan 2016 14:28:02 -0600 Subject: [PATCH] Remove regex guess on counting query - replace with explicit set on Count() call to fix order by issues --- scope_private.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/scope_private.go b/scope_private.go index fa5d5f44..6209f8e5 100644 --- a/scope_private.go +++ b/scope_private.go @@ -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 }