mirror of https://github.com/go-gorm/gorm.git
Make sure UpdateColumn works with CamelCase
This commit is contained in:
parent
31c64a9c95
commit
7a789c82df
4
do.go
4
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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue