mirror of https://github.com/go-gorm/gorm.git
Check ReflectValue.CanAddr before set field value
This commit is contained in:
parent
15a46bc042
commit
d327926425
|
@ -36,7 +36,7 @@ var (
|
||||||
// ErrInvalidDB invalid db
|
// ErrInvalidDB invalid db
|
||||||
ErrInvalidDB = errors.New("invalid db")
|
ErrInvalidDB = errors.New("invalid db")
|
||||||
// ErrInvalidValue invalid value
|
// ErrInvalidValue invalid value
|
||||||
ErrInvalidValue = errors.New("invalid value")
|
ErrInvalidValue = errors.New("invalid value, should be pointer to struct or slice")
|
||||||
// ErrInvalidValueOfLength invalid values do not match length
|
// ErrInvalidValueOfLength invalid values do not match length
|
||||||
ErrInvalidValueOfLength = errors.New("invalid association values, length doesn't match")
|
ErrInvalidValueOfLength = errors.New("invalid association values, length doesn't match")
|
||||||
)
|
)
|
||||||
|
|
|
@ -539,6 +539,11 @@ func (stmt *Statement) SetColumn(name string, value interface{}, fromCallbacks .
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !stmt.ReflectValue.CanAddr() {
|
||||||
|
stmt.AddError(ErrInvalidValue)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
switch stmt.ReflectValue.Kind() {
|
switch stmt.ReflectValue.Kind() {
|
||||||
case reflect.Slice, reflect.Array:
|
case reflect.Slice, reflect.Array:
|
||||||
if len(fromCallbacks) > 0 {
|
if len(fromCallbacks) > 0 {
|
||||||
|
|
Loading…
Reference in New Issue