mirror of https://github.com/go-gorm/gorm.git
Fix panic: reflect.Value.Addr of unaddressable value
This commit is contained in:
parent
19aacb8fbb
commit
7f1a4cf301
13
preload.go
13
preload.go
|
@ -337,15 +337,24 @@ func (scope *Scope) getColumnsAsScope(column string) *Scope {
|
||||||
}
|
}
|
||||||
if column.Kind() == reflect.Slice {
|
if column.Kind() == reflect.Slice {
|
||||||
for i := 0; i < column.Len(); i++ {
|
for i := 0; i < column.Len(); i++ {
|
||||||
columns = reflect.Append(columns, column.Index(i).Addr())
|
elem := column.Index(i)
|
||||||
|
if elem.CanAddr() {
|
||||||
|
columns = reflect.Append(columns, elem.Addr())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if column.CanAddr() {
|
||||||
columns = reflect.Append(columns, column.Addr())
|
columns = reflect.Append(columns, column.Addr())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return scope.New(columns.Interface())
|
return scope.New(columns.Interface())
|
||||||
case reflect.Struct:
|
case reflect.Struct:
|
||||||
return scope.New(values.FieldByName(column).Addr().Interface())
|
field := values.FieldByName(column)
|
||||||
|
if !field.CanAddr() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return scope.New(field.Addr().Interface())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue