Fix update join for databases except sqlite

This commit is contained in:
Lunny Xiao 2023-12-22 23:29:44 +08:00
parent b23798dc98
commit 22d763c312
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
2 changed files with 10 additions and 3 deletions

View File

@ -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 {

View File

@ -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)
}
*/