From 22d763c312c5bcf20ce7f13924cbc42305bb6eaf Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 22 Dec 2023 23:29:44 +0800 Subject: [PATCH] Fix update join for databases except sqlite --- internal/statements/update.go | 4 ++++ tests/session_update_test.go | 9 ++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/internal/statements/update.go b/internal/statements/update.go index cd09e7a9..53fc1136 100644 --- a/internal/statements/update.go +++ b/internal/statements/update.go @@ -626,6 +626,10 @@ func (statement *Statement) WriteUpdate(updateWriter *builder.BytesWriter, cond return err } + if err := statement.writeJoins(updateWriter); err != nil { + return err + } + if statement.dialect.URI().DBType == schemas.MSSQL { table := statement.RefTable if statement.HasOrderBy() && table != nil && len(table.PrimaryKeys) == 1 { diff --git a/tests/session_update_test.go b/tests/session_update_test.go index 3528e6d0..900f58b1 100644 --- a/tests/session_update_test.go +++ b/tests/session_update_test.go @@ -1472,8 +1472,12 @@ func TestNilFromDB(t *testing.T) { assert.NotNil(t, tt4.Field1.cb) } -/* func TestUpdateWithJoin(t *testing.T) { + if testEngine.Dialect().URI().DBType == schemas.SQLITE { + t.Skip() + return + } + type TestUpdateWithJoin struct { Id int64 ExtId int64 @@ -1497,8 +1501,7 @@ func TestUpdateWithJoin(t *testing.T) { _, err = testEngine.Table("test_update_with_join"). Join("INNER", "test_update_with_join2", "test_update_with_join.ext_id = test_update_with_join2.id"). - Where("test_update_with_join2.name = ?", "test"). + Where("test_update_with_join2.`name` = ?", "test"). Update(&TestUpdateWithJoin{Name: "test2"}) assert.NoError(t, err) } -*/