bug fixed for update which includes json struct fields
This commit is contained in:
parent
a0e63df407
commit
8bf440560e
12
statement.go
12
statement.go
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue