MCPcopy
hub / github.com/go-gorm/gorm / BeforeUpdate

Method BeforeUpdate

tests/hooks_test.go:313–323  ·  view source on GitHub ↗
(tx *gorm.DB)

Source from the content-addressed store, hash-verified

311}
312
313func (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
325func TestSetColumn(t *testing.T) {
326 DB.Migrator().DropTable(&Product3{})

Callers

nothing calls this directly

Calls 2

ChangedMethod · 0.80
SetColumnMethod · 0.80

Tested by

no test coverage detected