mirror of https://github.com/go-gorm/gorm.git
Do not always override select on pluck
This commit is contained in:
parent
4c93473b2d
commit
841ea1bde5
18
scope.go
18
scope.go
|
@ -938,14 +938,30 @@ func (scope *Scope) initialize() *Scope {
|
|||
return scope
|
||||
}
|
||||
|
||||
func (scope *Scope) isQueryForColumn(query interface{}, column string) bool {
|
||||
queryStr := fmt.Sprint(query)
|
||||
if queryStr == column {
|
||||
return true
|
||||
}
|
||||
|
||||
if strings.HasSuffix(strings.ToLower(queryStr), "as "+column) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (scope *Scope) pluck(column string, value interface{}) *Scope {
|
||||
dest := reflect.Indirect(reflect.ValueOf(value))
|
||||
scope.Search.Select(column)
|
||||
if dest.Kind() != reflect.Slice {
|
||||
scope.Err(fmt.Errorf("results should be a slice, not %s", dest.Kind()))
|
||||
return scope
|
||||
}
|
||||
|
||||
if query, ok := scope.Search.selects["query"]; !ok || !scope.isQueryForColumn(query, column) {
|
||||
scope.Search.Select(column)
|
||||
}
|
||||
|
||||
rows, err := scope.rows()
|
||||
if scope.Err(err) == nil {
|
||||
defer rows.Close()
|
||||
|
|
Loading…
Reference in New Issue