(tx *gorm.DB)
| 311 | } |
| 312 | |
| 313 | func (s Product3) BeforeUpdate(tx *gorm.DB) (err error) { |
| 314 | if tx.Statement.Changed() { |
| 315 | tx.Statement.SetColumn("Price", s.Price+10) |
| 316 | } |
| 317 | |
| 318 | if tx.Statement.Changed("Code") { |
| 319 | s.Price += 20 |
| 320 | tx.Statement.SetColumn("Price", s.Price+30) |
| 321 | } |
| 322 | return nil |
| 323 | } |
| 324 | |
| 325 | func TestSetColumn(t *testing.T) { |
| 326 | DB.Migrator().DropTable(&Product3{}) |