mirror of https://github.com/go-gorm/gorm.git
Merge pull request #1132 from zardak/preload-dedupe
This commit is contained in:
parent
45fc640bf3
commit
066abcef40
30
scope.go
30
scope.go
|
@ -1216,29 +1216,43 @@ func (scope *Scope) autoIndex() *Scope {
|
||||||
|
|
||||||
func (scope *Scope) getColumnAsArray(columns []string, values ...interface{}) (results [][]interface{}) {
|
func (scope *Scope) getColumnAsArray(columns []string, values ...interface{}) (results [][]interface{}) {
|
||||||
for _, value := range values {
|
for _, value := range values {
|
||||||
indirectValue := reflect.ValueOf(value)
|
indirectValue := indirect(reflect.ValueOf(value))
|
||||||
for indirectValue.Kind() == reflect.Ptr {
|
|
||||||
indirectValue = indirectValue.Elem()
|
|
||||||
}
|
|
||||||
|
|
||||||
switch indirectValue.Kind() {
|
switch indirectValue.Kind() {
|
||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
for i := 0; i < indirectValue.Len(); i++ {
|
for i := 0; i < indirectValue.Len(); i++ {
|
||||||
var result []interface{}
|
var result []interface{}
|
||||||
var object = indirect(indirectValue.Index(i))
|
var object = indirect(indirectValue.Index(i))
|
||||||
|
var hasValue = false
|
||||||
for _, column := range columns {
|
for _, column := range columns {
|
||||||
result = append(result, object.FieldByName(column).Interface())
|
field := object.FieldByName(column)
|
||||||
|
if hasValue || !isBlank(field) {
|
||||||
|
hasValue = true
|
||||||
|
}
|
||||||
|
result = append(result, field.Interface())
|
||||||
|
}
|
||||||
|
|
||||||
|
if hasValue {
|
||||||
|
results = append(results, result)
|
||||||
}
|
}
|
||||||
results = append(results, result)
|
|
||||||
}
|
}
|
||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
var result []interface{}
|
var result []interface{}
|
||||||
|
var hasValue = false
|
||||||
for _, column := range columns {
|
for _, column := range columns {
|
||||||
result = append(result, indirectValue.FieldByName(column).Interface())
|
field := indirectValue.FieldByName(column)
|
||||||
|
if hasValue || !isBlank(field) {
|
||||||
|
hasValue = true
|
||||||
|
}
|
||||||
|
result = append(result, field.Interface())
|
||||||
|
}
|
||||||
|
|
||||||
|
if hasValue {
|
||||||
|
results = append(results, result)
|
||||||
}
|
}
|
||||||
results = append(results, result)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue