diff --git a/scope_private.go b/scope_private.go index aa685cd6..31c7809c 100644 --- a/scope_private.go +++ b/scope_private.go @@ -211,14 +211,7 @@ func (scope *Scope) selectSql() string { if len(scope.Search.Selects) == 0 { return "*" } - - var selectQueries []string - - for _, clause := range scope.Search.Selects { - selectQueries = append(selectQueries, scope.buildSelectQuery(clause)) - } - - return strings.Join(selectQueries, ", ") + return scope.buildSelectQuery(scope.Search.Selects) } func (scope *Scope) orderSql() string { @@ -370,9 +363,7 @@ func (scope *Scope) pluck(column string, value interface{}) *Scope { } func (scope *Scope) count(value interface{}) *Scope { - scope.Search = scope.Search.clone() - scope.Search.Selects = []map[string]interface{}{} - scope.Search.selects("count(*)") + scope.Search = scope.Search.clone().selects("count(*)") scope.Err(scope.row().Scan(value)) return scope } diff --git a/search.go b/search.go index 51ec62da..75b1285a 100644 --- a/search.go +++ b/search.go @@ -7,12 +7,12 @@ type search struct { WhereConditions []map[string]interface{} OrConditions []map[string]interface{} NotConditions []map[string]interface{} + HavingCondition map[string]interface{} InitAttrs []interface{} AssignAttrs []interface{} - HavingCondition map[string]interface{} + Selects map[string]interface{} Orders []string Joins string - Selects []map[string]interface{} Preload map[string][]interface{} Offset string Limit string @@ -28,17 +28,17 @@ func (s *search) clone() *search { WhereConditions: s.WhereConditions, OrConditions: s.OrConditions, NotConditions: s.NotConditions, + HavingCondition: s.HavingCondition, InitAttrs: s.InitAttrs, AssignAttrs: s.AssignAttrs, - HavingCondition: s.HavingCondition, - Orders: s.Orders, Selects: s.Selects, + Orders: s.Orders, + Joins: s.Joins, Offset: s.Offset, Limit: s.Limit, - Unscope: s.Unscope, Group: s.Group, - Joins: s.Joins, TableName: s.TableName, + Unscope: s.Unscope, Raw: s.Raw, } } @@ -78,7 +78,7 @@ func (s *search) order(value string, reorder ...bool) *search { } func (s *search) selects(query interface{}, args ...interface{}) *search { - s.Selects = append(s.Selects, map[string]interface{}{"query": query, "args": args}) + s.Selects = map[string]interface{}{"query": query, "args": args} return s }