bug fixed for update which includes json struct fields

This commit is contained in:
Lunny Xiao 2015-10-29 13:30:22 +08:00
parent a0e63df407
commit 8bf440560e
3 changed files with 26 additions and 14 deletions

View File

@ -1 +1 @@
xorm v0.4.4.1027 xorm v0.4.4.1029

View File

@ -332,6 +332,7 @@ func buildUpdates(engine *Engine, table *core.Table, bean interface{},
} else if nulType, ok := fieldValue.Interface().(driver.Valuer); ok { } else if nulType, ok := fieldValue.Interface().(driver.Valuer); ok {
val, _ = nulType.Value() val, _ = nulType.Value()
} else { } else {
if !col.SQLType.IsJson() {
engine.autoMapType(fieldValue) engine.autoMapType(fieldValue)
if table, ok := engine.Tables[fieldValue.Type()]; ok { if table, ok := engine.Tables[fieldValue.Type()]; ok {
if len(table.PrimaryKeys) == 1 { if len(table.PrimaryKeys) == 1 {
@ -350,6 +351,17 @@ func buildUpdates(engine *Engine, table *core.Table, bean interface{},
} else { } else {
val = fieldValue.Interface() val = fieldValue.Interface()
} }
} else {
bytes, err := json.Marshal(fieldValue.Interface())
if err != nil {
panic(fmt.Sprintf("mashal %v failed", fieldValue.Interface()))
}
if col.SQLType.IsText() {
val = string(bytes)
} else if col.SQLType.IsBlob() {
val = bytes
}
}
} }
case reflect.Array, reflect.Slice, reflect.Map: case reflect.Array, reflect.Slice, reflect.Map:
if fieldValue == reflect.Zero(fieldType) { if fieldValue == reflect.Zero(fieldType) {

View File

@ -17,7 +17,7 @@ import (
) )
const ( const (
Version string = "0.4.4.1027" Version string = "0.4.4.1029"
) )
func regDrvsNDialects() bool { func regDrvsNDialects() bool {