Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
demoManito committed Aug 26, 2024
1 parent 080429f commit baaff00
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions tests/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,10 +638,15 @@ func TestBeforeUpdateWithStructColumn(t *testing.T) {
t.Fatalf("create struct failed: %v", err)
}

sql := DB.ToSQL(func(tx *gorm.DB) *gorm.DB {
return tx.Model(&su).Update("name", "demoManito")
})
if sql != "UPDATE `struct_updates` SET `name`='demoManito',`version`=2 WHERE `id` = 1" {
t.Fatalf("invalid sql: %v", sql)
err = DB.Model(&su).Update("name", "demoManito").Error
if err != nil {
t.Fatalf("update struct failed: %v", err)
}
if su.Version != 2 {
t.Fatalf("update version failed: %v", su.Version)
}
err = DB.Find(&su, "id = ?", 1).Error
if err != nil {
t.Fatalf("find struct failed: %v", err)
}
}

0 comments on commit baaff00

Please sign in to comment.