From a0ca3d61d6ab36f960b31a969081ead439701ffc Mon Sep 17 00:00:00 2001 From: BaoyangChai Date: Wed, 8 May 2019 23:11:57 +0800 Subject: [PATCH] update --- orm/db.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/orm/db.go b/orm/db.go index 20d9c4cd..2148daaa 100644 --- a/orm/db.go +++ b/orm/db.go @@ -621,20 +621,31 @@ func (d *dbBase) Update(q dbQuerier, mi *modelInfo, ind reflect.Value, tz *time. return 0, err } - var find bool + var findAutoNowAdd, findAutoNow bool var index int for i, col := range setNames { if mi.fields.GetByColumn(col).autoNowAdd { index = i - find = true + findAutoNowAdd = true + } + if mi.fields.GetByColumn(col).autoNow { + findAutoNow = true } } - - if find { + if findAutoNowAdd { setNames = append(setNames[0:index], setNames[index+1:]...) setValues = append(setValues[0:index], setValues[index+1:]...) } + if !findAutoNow { + for col, info := range mi.fields.columns { + if info.autoNow { + setNames = append(setNames, col) + setValues = append(setValues, time.Now()) + } + } + } + setValues = append(setValues, pkValue) Q := d.ins.TableQuote()