diff --git a/tests/hooks_test.go b/tests/hooks_test.go index 0d4ca7784..8d259872d 100644 --- a/tests/hooks_test.go +++ b/tests/hooks_test.go @@ -610,35 +610,35 @@ func TestPropagateUnscoped(t *testing.T) { } } -type UserUpdate struct { +type StructUpdate struct { ID uint `gorm:"column:id;primary_key"` Version int `gorm:"column:version"` Name string `gorm:"column:name"` } -func (UserUpdate) TableName() string { - return "user_updates" +func (StructUpdate) TableName() string { + return "struct_updates" } -func (up *UserUpdate) BeforeUpdate(tx *gorm.DB) error { +func (up *StructUpdate) BeforeUpdate(tx *gorm.DB) error { up.Version++ return nil } func TestBeforeUpdateWithStructColumn(t *testing.T) { - DB.Migrator().DropTable(&UserUpdate{}) - DB.AutoMigrate(&UserUpdate{}) + DB.Migrator().DropTable(&StructUpdate{}) + DB.AutoMigrate(&StructUpdate{}) - user := UserUpdate{ + su := StructUpdate{ ID: 1, Version: 1, } - DB.Create(&user) + DB.Create(&su) sql := DB.ToSQL(func(tx *gorm.DB) *gorm.DB { - return DB.Model(&user).Update("name", "demoManito") + return DB.Model(&su).Update("name", "demoManito") }) - if sql != "UPDATE `user_updates` SET `user_updates`.`name` = `demoManito`, `user_updates`.`version` = 2 WHERE `user_updates`.`id` = 1" { + if sql != "UPDATE `struct_updates` SET `user_updates`.`name` = `demoManito`, `user_updates`.`version` = 2 WHERE `user_updates`.`id` = 1" { t.Fatalf("invalid sql: %v", sql) } }