Skip to content

Commit

Permalink
getValueFromFields doesn't panic on nil pointers (go-gorm#2021)
Browse files Browse the repository at this point in the history
* `IsValid()` won't return `false` for nil pointers unless Value
  is wrapped in a `reflect.Indirect`.
  • Loading branch information
brunoro authored and jinzhu committed Sep 9, 2018
1 parent 012d147 commit 26fde91
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func getValueFromFields(value reflect.Value, fieldNames []string) (results []int
// as FieldByName could panic
if indirectValue := reflect.Indirect(value); indirectValue.IsValid() {
for _, fieldName := range fieldNames {
if fieldValue := indirectValue.FieldByName(fieldName); fieldValue.IsValid() {
if fieldValue := reflect.Indirect(indirectValue.FieldByName(fieldName)); fieldValue.IsValid() {
result := fieldValue.Interface()
if r, ok := result.(driver.Valuer); ok {
result, _ = r.Value()
Expand Down

0 comments on commit 26fde91

Please sign in to comment.