mirror of https://github.com/go-gorm/gorm.git
Merge pull request #457 from li3p/master
look up the Field.Name in Scope.SetColumn
This commit is contained in:
commit
e3d70302f3
11
scope.go
11
scope.go
|
@ -158,13 +158,18 @@ func (scope *Scope) HasColumn(column string) bool {
|
||||||
func (scope *Scope) SetColumn(column interface{}, value interface{}) error {
|
func (scope *Scope) SetColumn(column interface{}, value interface{}) error {
|
||||||
if field, ok := column.(*Field); ok {
|
if field, ok := column.(*Field); ok {
|
||||||
return field.Set(value)
|
return field.Set(value)
|
||||||
} else if dbName, ok := column.(string); ok {
|
} else if name, ok := column.(string); ok {
|
||||||
|
|
||||||
|
if field, ok := scope.Fields()[name]; ok {
|
||||||
|
return field.Set(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
dbName := ToDBName(name)
|
||||||
if field, ok := scope.Fields()[dbName]; ok {
|
if field, ok := scope.Fields()[dbName]; ok {
|
||||||
return field.Set(value)
|
return field.Set(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
dbName = ToDBName(dbName)
|
if field, ok := scope.FieldByName(name); ok {
|
||||||
if field, ok := scope.Fields()[dbName]; ok {
|
|
||||||
return field.Set(value)
|
return field.Set(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue