mirror of
https://github.com/astaxie/beego.git
synced 2024-11-25 19:50:55 +00:00
orm insert skip auto_now_add when user custom a value
This commit is contained in:
parent
a54353b51c
commit
b310be1fcf
@ -144,6 +144,11 @@ func (d *dbBase) collectFieldValue(mi *modelInfo, fi *fieldInfo, ind reflect.Val
|
|||||||
switch fi.fieldType {
|
switch fi.fieldType {
|
||||||
case TypeDateField, TypeDateTimeField:
|
case TypeDateField, TypeDateTimeField:
|
||||||
if fi.auto_now || fi.auto_now_add && insert {
|
if fi.auto_now || fi.auto_now_add && insert {
|
||||||
|
if insert {
|
||||||
|
if t, ok := value.(time.Time); ok && !t.IsZero() {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
tnow := time.Now()
|
tnow := time.Now()
|
||||||
d.ins.TimeToDB(&tnow, tz)
|
d.ins.TimeToDB(&tnow, tz)
|
||||||
value = tnow
|
value = tnow
|
||||||
|
Loading…
Reference in New Issue
Block a user