From b310be1fcf5ef725df2700cdb05f676ee17e479a Mon Sep 17 00:00:00 2001 From: slene Date: Thu, 20 Feb 2014 13:45:31 +0800 Subject: [PATCH] orm insert skip auto_now_add when user custom a value --- orm/db.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/orm/db.go b/orm/db.go index 60e53765..00945e43 100644 --- a/orm/db.go +++ b/orm/db.go @@ -144,6 +144,11 @@ func (d *dbBase) collectFieldValue(mi *modelInfo, fi *fieldInfo, ind reflect.Val switch fi.fieldType { case TypeDateField, TypeDateTimeField: if fi.auto_now || fi.auto_now_add && insert { + if insert { + if t, ok := value.(time.Time); ok && !t.IsZero() { + break + } + } tnow := time.Now() d.ins.TimeToDB(&tnow, tz) value = tnow