Raise error if using unaddressable value

This commit is contained in:
Jinzhu 2015-02-23 09:40:39 +08:00
parent 7934223f99
commit a97a508ec7
3 changed files with 7 additions and 7 deletions

View File

@ -61,7 +61,7 @@ func Create(scope *Scope) {
if scope.Err(err) == nil {
scope.db.RowsAffected, _ = result.RowsAffected()
if primaryField != nil {
scope.SetColumn(primaryField, id)
scope.Err(scope.SetColumn(primaryField, id))
}
}
}

View File

@ -21,7 +21,7 @@ func SaveBeforeAssociations(scope *Scope) {
value := field.Field
scope.Err(scope.NewDB().Save(value.Addr().Interface()).Error)
if relationship.ForeignFieldName != "" {
scope.SetColumn(relationship.ForeignFieldName, scope.New(value.Addr().Interface()).PrimaryKeyValue())
scope.Err(scope.SetColumn(relationship.ForeignFieldName, scope.New(value.Addr().Interface()).PrimaryKeyValue()))
}
}
}
@ -43,11 +43,11 @@ func SaveAfterAssociations(scope *Scope) {
newScope := newDB.NewScope(elem)
if relationship.JoinTable == "" && relationship.ForeignFieldName != "" {
newScope.SetColumn(relationship.ForeignFieldName, scope.PrimaryKeyValue())
scope.Err(newScope.SetColumn(relationship.ForeignFieldName, scope.PrimaryKeyValue()))
}
if relationship.PolymorphicType != "" {
newScope.SetColumn(relationship.PolymorphicType, scope.TableName())
scope.Err(newScope.SetColumn(relationship.PolymorphicType, scope.TableName()))
}
scope.Err(newDB.Save(elem).Error)
@ -77,11 +77,11 @@ func SaveAfterAssociations(scope *Scope) {
elem := value.Addr().Interface()
newScope := scope.New(elem)
if relationship.ForeignFieldName != "" {
newScope.SetColumn(relationship.ForeignFieldName, scope.PrimaryKeyValue())
scope.Err(newScope.SetColumn(relationship.ForeignFieldName, scope.PrimaryKeyValue()))
}
if relationship.PolymorphicType != "" {
newScope.SetColumn(relationship.PolymorphicType, scope.TableName())
scope.Err(newScope.SetColumn(relationship.PolymorphicType, scope.TableName()))
}
scope.Err(scope.NewDB().Save(elem).Error)
}

View File

@ -18,7 +18,7 @@ func (field *Field) Set(value interface{}) error {
}
if !field.Field.CanAddr() {
return errors.New("field value not addressable")
return errors.New("unaddressable value")
}
if rvalue, ok := value.(reflect.Value); ok {