mirror of https://github.com/go-gorm/gorm.git
Check valid pointer before use it as Valuer
This commit is contained in:
parent
06de6e8834
commit
f88e8b072c
|
@ -473,16 +473,16 @@ func (field *Field) setupValuerAndSetter() {
|
|||
}
|
||||
}
|
||||
|
||||
if valuer, ok := v.(driver.Valuer); ok {
|
||||
if v, err = valuer.Value(); err == nil {
|
||||
err = setter(value, v)
|
||||
}
|
||||
} else if reflectV.Kind() == reflect.Ptr {
|
||||
if reflectV.Kind() == reflect.Ptr {
|
||||
if reflectV.IsNil() {
|
||||
field.ReflectValueOf(value).Set(reflect.New(field.FieldType).Elem())
|
||||
} else {
|
||||
err = setter(value, reflectV.Elem().Interface())
|
||||
}
|
||||
} else if valuer, ok := v.(driver.Valuer); ok {
|
||||
if v, err = valuer.Value(); err == nil {
|
||||
err = setter(value, v)
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("failed to set value %+v to field %v", v, field.Name)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue