Merge pull request #520 from crystalin/master

Support for preload of Struct Ptr
This commit is contained in:
Jinzhu 2015-06-08 09:30:37 +08:00
commit b3d62fafc3
1 changed files with 4 additions and 1 deletions

View File

@ -216,13 +216,16 @@ func (scope *Scope) getColumnsAsScope(column string) *Scope {
} }
fieldStruct, _ := modelType.FieldByName(column) fieldStruct, _ := modelType.FieldByName(column)
var columns reflect.Value var columns reflect.Value
if fieldStruct.Type.Kind() == reflect.Slice { if fieldStruct.Type.Kind() == reflect.Slice || fieldStruct.Type.Kind() == reflect.Ptr {
columns = reflect.New(reflect.SliceOf(reflect.PtrTo(fieldStruct.Type.Elem()))).Elem() columns = reflect.New(reflect.SliceOf(reflect.PtrTo(fieldStruct.Type.Elem()))).Elem()
} else { } else {
columns = reflect.New(reflect.SliceOf(reflect.PtrTo(fieldStruct.Type))).Elem() columns = reflect.New(reflect.SliceOf(reflect.PtrTo(fieldStruct.Type))).Elem()
} }
for i := 0; i < values.Len(); i++ { for i := 0; i < values.Len(); i++ {
column := reflect.Indirect(values.Index(i)).FieldByName(column) column := reflect.Indirect(values.Index(i)).FieldByName(column)
if column.Kind() == reflect.Ptr {
column = column.Elem()
}
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()) columns = reflect.Append(columns, column.Index(i).Addr())