mirror of https://github.com/go-gorm/gorm.git
Overwrite Select conditions
This commit is contained in:
parent
49a33dd5d0
commit
068e774540
|
@ -211,14 +211,7 @@ func (scope *Scope) selectSql() string {
|
||||||
if len(scope.Search.Selects) == 0 {
|
if len(scope.Search.Selects) == 0 {
|
||||||
return "*"
|
return "*"
|
||||||
}
|
}
|
||||||
|
return scope.buildSelectQuery(scope.Search.Selects)
|
||||||
var selectQueries []string
|
|
||||||
|
|
||||||
for _, clause := range scope.Search.Selects {
|
|
||||||
selectQueries = append(selectQueries, scope.buildSelectQuery(clause))
|
|
||||||
}
|
|
||||||
|
|
||||||
return strings.Join(selectQueries, ", ")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (scope *Scope) orderSql() string {
|
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 {
|
func (scope *Scope) count(value interface{}) *Scope {
|
||||||
scope.Search = scope.Search.clone()
|
scope.Search = scope.Search.clone().selects("count(*)")
|
||||||
scope.Search.Selects = []map[string]interface{}{}
|
|
||||||
scope.Search.selects("count(*)")
|
|
||||||
scope.Err(scope.row().Scan(value))
|
scope.Err(scope.row().Scan(value))
|
||||||
return scope
|
return scope
|
||||||
}
|
}
|
||||||
|
|
14
search.go
14
search.go
|
@ -7,12 +7,12 @@ type search struct {
|
||||||
WhereConditions []map[string]interface{}
|
WhereConditions []map[string]interface{}
|
||||||
OrConditions []map[string]interface{}
|
OrConditions []map[string]interface{}
|
||||||
NotConditions []map[string]interface{}
|
NotConditions []map[string]interface{}
|
||||||
|
HavingCondition map[string]interface{}
|
||||||
InitAttrs []interface{}
|
InitAttrs []interface{}
|
||||||
AssignAttrs []interface{}
|
AssignAttrs []interface{}
|
||||||
HavingCondition map[string]interface{}
|
Selects map[string]interface{}
|
||||||
Orders []string
|
Orders []string
|
||||||
Joins string
|
Joins string
|
||||||
Selects []map[string]interface{}
|
|
||||||
Preload map[string][]interface{}
|
Preload map[string][]interface{}
|
||||||
Offset string
|
Offset string
|
||||||
Limit string
|
Limit string
|
||||||
|
@ -28,17 +28,17 @@ func (s *search) clone() *search {
|
||||||
WhereConditions: s.WhereConditions,
|
WhereConditions: s.WhereConditions,
|
||||||
OrConditions: s.OrConditions,
|
OrConditions: s.OrConditions,
|
||||||
NotConditions: s.NotConditions,
|
NotConditions: s.NotConditions,
|
||||||
|
HavingCondition: s.HavingCondition,
|
||||||
InitAttrs: s.InitAttrs,
|
InitAttrs: s.InitAttrs,
|
||||||
AssignAttrs: s.AssignAttrs,
|
AssignAttrs: s.AssignAttrs,
|
||||||
HavingCondition: s.HavingCondition,
|
|
||||||
Orders: s.Orders,
|
|
||||||
Selects: s.Selects,
|
Selects: s.Selects,
|
||||||
|
Orders: s.Orders,
|
||||||
|
Joins: s.Joins,
|
||||||
Offset: s.Offset,
|
Offset: s.Offset,
|
||||||
Limit: s.Limit,
|
Limit: s.Limit,
|
||||||
Unscope: s.Unscope,
|
|
||||||
Group: s.Group,
|
Group: s.Group,
|
||||||
Joins: s.Joins,
|
|
||||||
TableName: s.TableName,
|
TableName: s.TableName,
|
||||||
|
Unscope: s.Unscope,
|
||||||
Raw: s.Raw,
|
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 {
|
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
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue