430a0a97 by slene Committed by asta.xie

orm insert skip auto_now_add when user custom a value

1 parent 5be22a99
...@@ -144,6 +144,11 @@ func (d *dbBase) collectFieldValue(mi *modelInfo, fi *fieldInfo, ind reflect.Val ...@@ -144,6 +144,11 @@ func (d *dbBase) collectFieldValue(mi *modelInfo, fi *fieldInfo, ind reflect.Val
144 switch fi.fieldType { 144 switch fi.fieldType {
145 case TypeDateField, TypeDateTimeField: 145 case TypeDateField, TypeDateTimeField:
146 if fi.auto_now || fi.auto_now_add && insert { 146 if fi.auto_now || fi.auto_now_add && insert {
147 if insert {
148 if t, ok := value.(time.Time); ok && !t.IsZero() {
149 break
150 }
151 }
147 tnow := time.Now() 152 tnow := time.Now()
148 d.ins.TimeToDB(&tnow, tz) 153 d.ins.TimeToDB(&tnow, tz)
149 value = tnow 154 value = tnow
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!