forked from mirror/gorm
getValueFromFields doesn't panic on nil pointers (#2021)
* `IsValid()` won't return `false` for nil pointers unless Value is wrapped in a `reflect.Indirect`.
This commit is contained in:
parent
012d147974
commit
26fde9110f
2
utils.go
2
utils.go
|
@ -206,7 +206,7 @@ func getValueFromFields(value reflect.Value, fieldNames []string) (results []int
|
||||||
// as FieldByName could panic
|
// as FieldByName could panic
|
||||||
if indirectValue := reflect.Indirect(value); indirectValue.IsValid() {
|
if indirectValue := reflect.Indirect(value); indirectValue.IsValid() {
|
||||||
for _, fieldName := range fieldNames {
|
for _, fieldName := range fieldNames {
|
||||||
if fieldValue := indirectValue.FieldByName(fieldName); fieldValue.IsValid() {
|
if fieldValue := reflect.Indirect(indirectValue.FieldByName(fieldName)); fieldValue.IsValid() {
|
||||||
result := fieldValue.Interface()
|
result := fieldValue.Interface()
|
||||||
if r, ok := result.(driver.Valuer); ok {
|
if r, ok := result.(driver.Valuer); ok {
|
||||||
result, _ = r.Value()
|
result, _ = r.Value()
|
||||||
|
|
Loading…
Reference in New Issue