diff --git a/do.go b/do.go index 49b76835..e3aeff47 100644 --- a/do.go +++ b/do.go @@ -208,7 +208,9 @@ func (s *Do) convertToMapInterface(values interface{}) map[string]interface{} { switch value := values.(type) { case map[string]interface{}: - attrs = value + for k, v := range value { + attrs[toSnake(k)] = v + } case []interface{}: for _, v := range value { for key, value := range s.convertToMapInterface(v) { diff --git a/gorm_test.go b/gorm_test.go index ee703a5c..d130a728 100644 --- a/gorm_test.go +++ b/gorm_test.go @@ -868,6 +868,14 @@ func TestUpdate(t *testing.T) { if db.First(&Product{}, "code = '789'").Error != nil { t.Errorf("Product 456 should be changed to 789") } + + if db.Model(&product2).Update("CreatedAt", time.Now().Add(time.Hour)).Error != nil { + t.Error("No error should raise when update with CamelCase") + } + + if db.Model(&product2).UpdateColumn("CreatedAt", time.Now().Add(time.Hour)).Error != nil { + t.Error("No error should raise when update_column with CamelCase") + } } func TestUpdates(t *testing.T) { diff --git a/model.go b/model.go index 4494306f..17517dca 100644 --- a/model.go +++ b/model.go @@ -132,6 +132,7 @@ func (m *Model) updatedColumnsAndValues(values map[string]interface{}, ignore_pr data := m.reflectData() if !data.CanAddr() { + m.do.err(errors.New("Can't take address of the object")) return }