Skip to content

Commit

Permalink
Overwrite Select conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Feb 23, 2015
1 parent 49a33dd commit 068e774
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
13 changes: 2 additions & 11 deletions scope_private.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
14 changes: 7 additions & 7 deletions search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
}
}
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 068e774

Please sign in to comment.