type User struct { gorm.Model CreditCard CreditCard // ... }
func(u *User) BeforeCreate(tx *gorm.DB) error { myValue, ok := tx.InstanceGet("my_value") // ok => true // myValue => 123 }
type CreditCard struct { gorm.Model // ... }
// When creating associations, GORM creates a new `*Statement`, so can't read other instance's settings func(card *CreditCard) BeforeCreate(tx *gorm.DB) error { myValue, ok := tx.InstanceGet("my_value") // ok => false // myValue => nil }