fix conflicts between Cols and updated (#725)
This commit is contained in:
parent
c29485f954
commit
3101e3bc44
|
@ -202,6 +202,7 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
|
||||||
table := session.statement.RefTable
|
table := session.statement.RefTable
|
||||||
|
|
||||||
if session.statement.UseAutoTime && table != nil && table.Updated != "" {
|
if session.statement.UseAutoTime && table != nil && table.Updated != "" {
|
||||||
|
if _, ok := session.statement.columnMap[strings.ToLower(table.Updated)]; !ok {
|
||||||
colNames = append(colNames, session.engine.Quote(table.Updated)+" = ?")
|
colNames = append(colNames, session.engine.Quote(table.Updated)+" = ?")
|
||||||
col := table.UpdatedColumn()
|
col := table.UpdatedColumn()
|
||||||
val, t := session.engine.NowTime2(col.SQLType.Name)
|
val, t := session.engine.NowTime2(col.SQLType.Name)
|
||||||
|
@ -215,6 +216,7 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//for update action to like "column = column + ?"
|
//for update action to like "column = column + ?"
|
||||||
incColumns := session.statement.getInc()
|
incColumns := session.statement.getInc()
|
||||||
|
|
|
@ -1153,3 +1153,20 @@ func TestNewUpdate(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.EqualValues(t, 0, af)
|
assert.EqualValues(t, 0, af)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUpdateUpdate(t *testing.T) {
|
||||||
|
assert.NoError(t, prepareEngine())
|
||||||
|
|
||||||
|
type PublicKeyUpdate struct {
|
||||||
|
Id int64
|
||||||
|
UpdatedUnix int64 `xorm:"updated"`
|
||||||
|
}
|
||||||
|
|
||||||
|
assertSync(t, new(PublicKeyUpdate))
|
||||||
|
|
||||||
|
cnt, err := testEngine.ID(1).Cols("updated_unix").Update(&PublicKeyUpdate{
|
||||||
|
UpdatedUnix: time.Now().Unix(),
|
||||||
|
})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.EqualValues(t, 0, cnt)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue