mirror of https://github.com/go-gorm/gorm.git
Convert string to int automatically when query and update
This commit is contained in:
parent
41d8e2d132
commit
49fa9c7f4a
8
model.go
8
model.go
|
@ -5,6 +5,7 @@ import (
|
||||||
"go/ast"
|
"go/ast"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -141,6 +142,13 @@ func (m *Model) updatedColumnsAndValues(values map[string]interface{}, ignore_pr
|
||||||
if field.Interface() != value {
|
if field.Interface() != value {
|
||||||
switch field.Kind() {
|
switch field.Kind() {
|
||||||
case reflect.Int, reflect.Int32, reflect.Int64:
|
case reflect.Int, reflect.Int32, reflect.Int64:
|
||||||
|
if s, ok := value.(string); ok {
|
||||||
|
i, err := strconv.Atoi(s)
|
||||||
|
if m.do.err(err) == nil {
|
||||||
|
value = i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if field.Int() != reflect.ValueOf(value).Int() {
|
if field.Int() != reflect.ValueOf(value).Int() {
|
||||||
any_updated = true
|
any_updated = true
|
||||||
field.SetInt(reflect.ValueOf(value).Int())
|
field.SetInt(reflect.ValueOf(value).Int())
|
||||||
|
|
Loading…
Reference in New Issue