From ebe5f191a915d3928e92fe8e17330e2b34551f23 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Fri, 16 Jan 2015 10:02:04 +0800 Subject: [PATCH] Fix upper case for primary key --- scope.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scope.go b/scope.go index daf3acec..c53edfc0 100644 --- a/scope.go +++ b/scope.go @@ -163,12 +163,16 @@ func (scope *Scope) FieldValueByName(name string) (interface{}, error) { func (scope *Scope) SetColumn(column interface{}, value interface{}) error { if field, ok := column.(*Field); ok { return field.Set(value) - } else if str, ok := column.(string); ok { + } else if dbName, ok := column.(string); ok { if scope.Value == nil { return errors.New("scope value must not be nil for string columns") } - dbName := ToSnake(str) + if field, ok := scope.Fields()[dbName]; ok { + return field.Set(value) + } + + dbName = ToSnake(dbName) if field, ok := scope.Fields()[dbName]; ok { return field.Set(value)