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 +}