forked from mirror/gorm
Convert str to int if it is when set field
This commit is contained in:
parent
c387c7d9ba
commit
32dcacc70b
4
model.go
4
model.go
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strconv"
|
||||
|
||||
"time"
|
||||
)
|
||||
|
@ -244,6 +245,9 @@ func setFieldValue(field reflect.Value, value interface{}) {
|
|||
if field.IsValid() {
|
||||
switch field.Kind() {
|
||||
case reflect.Int, reflect.Int32, reflect.Int64:
|
||||
if str, ok := value.(string); ok {
|
||||
value, _ = strconv.Atoi(str)
|
||||
}
|
||||
field.SetInt(reflect.ValueOf(value).Int())
|
||||
default:
|
||||
field.Set(reflect.ValueOf(value))
|
||||
|
|
Loading…
Reference in New Issue