make count works

This commit is contained in:
Jinzhu 2014-01-28 11:38:53 +08:00
parent 5fd2e0d54f
commit ae68c0fb47
2 changed files with 7 additions and 1 deletions

View File

@ -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 {

View File

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