diff --git a/preload.go b/preload.go index dd85c327..4621dd91 100644 --- a/preload.go +++ b/preload.go @@ -337,15 +337,24 @@ func (scope *Scope) getColumnsAsScope(column string) *Scope { } if column.Kind() == reflect.Slice { 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 { - columns = reflect.Append(columns, column.Addr()) + if column.CanAddr() { + columns = reflect.Append(columns, column.Addr()) + } } } return scope.New(columns.Interface()) 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 }