From 34e75afb42007629e18aea20ed6722f151e62553 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Sun, 14 Aug 2016 15:15:09 +0800 Subject: [PATCH] Support specify count select argument --- scope.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scope.go b/scope.go index 2b9b21e7..48a87f58 100644 --- a/scope.go +++ b/scope.go @@ -917,7 +917,9 @@ func (scope *Scope) pluck(column string, value interface{}) *Scope { } func (scope *Scope) count(value interface{}) *Scope { - scope.Search.Select("count(*)") + if query, ok := scope.Search.selects["query"]; !ok || !strings.Contains(fmt.Sprint(query), "count(") { + scope.Search.Select("count(*)") + } scope.Search.countingQuery = true scope.Err(scope.row().Scan(value)) return scope