Print warning message when using unaddressable value with Update

This commit is contained in:
Jinzhu 2016-04-04 21:33:11 +08:00
parent c49e68fac2
commit 9fd05d1bad
3 changed files with 10 additions and 3 deletions

View File

@ -14,6 +14,8 @@ var (
ErrInvalidTransaction = errors.New("no valid transaction") ErrInvalidTransaction = errors.New("no valid transaction")
// ErrCantStartTransaction can't start transaction when you are trying to start one with `Begin` // ErrCantStartTransaction can't start transaction when you are trying to start one with `Begin`
ErrCantStartTransaction = errors.New("can't start transaction") ErrCantStartTransaction = errors.New("can't start transaction")
// ErrUnaddressable unaddressable value
ErrUnaddressable = errors.New("using unaddressable value")
) )
type errorsInterface interface { type errorsInterface interface {

View File

@ -21,7 +21,7 @@ func (field *Field) Set(value interface{}) (err error) {
} }
if !field.Field.CanAddr() { if !field.Field.CanAddr() {
return errors.New("unaddressable value") return ErrUnaddressable
} }
reflectValue, ok := value.(reflect.Value) reflectValue, ok := value.(reflect.Value)

View File

@ -846,10 +846,15 @@ func (scope *Scope) updatedAttrsWithValues(value interface{}) (results map[strin
hasUpdate = true hasUpdate = true
results[field.DBName] = value results[field.DBName] = value
} else { } else {
field.Set(value) err := field.Set(value)
if field.IsNormal { if field.IsNormal {
hasUpdate = true hasUpdate = true
results[field.DBName] = value if err == ErrUnaddressable {
fmt.Println(err)
results[field.DBName] = value
} else {
results[field.DBName] = field.Field.Interface()
}
} }
} }
} }