1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-26 02:51:28 +00:00
This commit is contained in:
BaoyangChai 2019-05-08 23:11:57 +08:00
parent 58b2ac702c
commit a0ca3d61d6

View File

@ -621,20 +621,31 @@ func (d *dbBase) Update(q dbQuerier, mi *modelInfo, ind reflect.Value, tz *time.
return 0, err return 0, err
} }
var find bool var findAutoNowAdd, findAutoNow bool
var index int var index int
for i, col := range setNames { for i, col := range setNames {
if mi.fields.GetByColumn(col).autoNowAdd { if mi.fields.GetByColumn(col).autoNowAdd {
index = i index = i
find = true findAutoNowAdd = true
}
if mi.fields.GetByColumn(col).autoNow {
findAutoNow = true
} }
} }
if findAutoNowAdd {
if find {
setNames = append(setNames[0:index], setNames[index+1:]...) setNames = append(setNames[0:index], setNames[index+1:]...)
setValues = append(setValues[0:index], setValues[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) setValues = append(setValues, pkValue)
Q := d.ins.TableQuote() Q := d.ins.TableQuote()