From ae68c0fb4709837b163e6deb3e56f00bc04bde5a Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Tue, 28 Jan 2014 11:38:53 +0800 Subject: [PATCH] make count works --- main.go | 2 +- scope.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index abf20c59..b262ad8f 100644 --- a/main.go +++ b/main.go @@ -228,7 +228,7 @@ func (s *DB) Pluck(column string, value interface{}) *DB { } func (s *DB) Count(value interface{}) *DB { - return s.do(s.Value).count(value).db + return s.NewScope(s.Value).count(value).db } func (s *DB) Table(name string) *DB { diff --git a/scope.go b/scope.go index aef54e51..41362452 100644 --- a/scope.go +++ b/scope.go @@ -424,3 +424,9 @@ func (scope *Scope) pluck(column string, value interface{}) *Scope { } return scope } + +func (scope *Scope) count(value interface{}) *Scope { + scope.Search = scope.Search.clone().selects("count(*)") + scope.Err(scope.row().Scan(value)) + return scope +}