Skip to content

Commit

Permalink
Print warning message when using unaddressable value with Update
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Apr 4, 2016
1 parent c49e68f commit 9fd05d1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions errors.go
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion field.go
Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions scope.go
Expand Up @@ -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
results[field.DBName] = value
if err == ErrUnaddressable {
fmt.Println(err)
results[field.DBName] = value
} else {
results[field.DBName] = field.Field.Interface()
}
}
}
}
Expand Down

0 comments on commit 9fd05d1

Please sign in to comment.