mirror of https://github.com/go-gorm/gorm.git
Print warning message when using unaddressable value with Update
This commit is contained in:
parent
c49e68fac2
commit
9fd05d1bad
|
@ -14,6 +14,8 @@ var (
|
|||
ErrInvalidTransaction = errors.New("no valid transaction")
|
||||
// ErrCantStartTransaction can't start transaction when you are trying to start one with `Begin`
|
||||
ErrCantStartTransaction = errors.New("can't start transaction")
|
||||
// ErrUnaddressable unaddressable value
|
||||
ErrUnaddressable = errors.New("using unaddressable value")
|
||||
)
|
||||
|
||||
type errorsInterface interface {
|
||||
|
|
2
field.go
2
field.go
|
@ -21,7 +21,7 @@ func (field *Field) Set(value interface{}) (err error) {
|
|||
}
|
||||
|
||||
if !field.Field.CanAddr() {
|
||||
return errors.New("unaddressable value")
|
||||
return ErrUnaddressable
|
||||
}
|
||||
|
||||
reflectValue, ok := value.(reflect.Value)
|
||||
|
|
7
scope.go
7
scope.go
|
@ -846,10 +846,15 @@ func (scope *Scope) updatedAttrsWithValues(value interface{}) (results map[strin
|
|||
hasUpdate = true
|
||||
results[field.DBName] = value
|
||||
} else {
|
||||
field.Set(value)
|
||||
err := field.Set(value)
|
||||
if field.IsNormal {
|
||||
hasUpdate = true
|
||||
if err == ErrUnaddressable {
|
||||
fmt.Println(err)
|
||||
results[field.DBName] = value
|
||||
} else {
|
||||
results[field.DBName] = field.Field.Interface()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue