diff --git a/session_update_test.go b/session_update_test.go index c90ec5bd9..e6c88bf8c 100644 --- a/session_update_test.go +++ b/session_update_test.go @@ -1390,3 +1390,34 @@ func TestUpdateDeleted(t *testing.T) { assert.NoError(t, err) assert.EqualValues(t, 1, cnt) } + +func TestUpdateExprs(t *testing.T) { + assert.NoError(t, prepareEngine()) + + type UpdateExprs struct { + Id int64 + NumIssues int + Name string + } + + assertSync(t, new(UpdateExprs)) + + _, err := testEngine.Insert(&UpdateExprs{ + NumIssues: 1, + Name: "lunny", + }) + assert.NoError(t, err) + + _, err = testEngine.SetExpr("num_issues", "num_issues+1").AllCols().Update(&UpdateExprs{ + NumIssues: 3, + Name: "lunny xiao", + }) + assert.NoError(t, err) + + var ue UpdateExprs + has, err := testEngine.Get(&ue) + assert.NoError(t, err) + assert.True(t, has) + assert.EqualValues(t, 2, ue.NumIssues) + assert.EqualValues(t, "lunny xiao", ue.Name) +} diff --git a/statement.go b/statement.go index 3cc0831ee..ae396c4ba 100644 --- a/statement.go +++ b/statement.go @@ -266,6 +266,14 @@ func (statement *Statement) buildUpdates(bean interface{}, continue } + if statement.incrColumns.isColExist(col.Name) { + continue + } else if statement.decrColumns.isColExist(col.Name) { + continue + } else if statement.exprColumns.isColExist(col.Name) { + continue + } + fieldValuePtr, err := col.ValueOf(bean) if err != nil { engine.logger.Error(err)