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

Function TestBelongsToDefaultValue

tests/associations_belongs_to_test.go:230–253  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

228}
229
230func TestBelongsToDefaultValue(t *testing.T) {
231 type Org struct {
232 ID string
233 }
234 type BelongsToUser struct {
235 OrgID string
236 Org Org `gorm:"default:NULL"`
237 }
238
239 tx := DB.Session(&gorm.Session{})
240 tx.Config.DisableForeignKeyConstraintWhenMigrating = true
241 AssertEqual(t, DB.Config.DisableForeignKeyConstraintWhenMigrating, false)
242
243 tx.Migrator().DropTable(&BelongsToUser{}, &Org{})
244 tx.AutoMigrate(&BelongsToUser{}, &Org{})
245
246 user := &BelongsToUser{
247 Org: Org{
248 ID: "BelongsToUser_Org_1",
249 },
250 }
251 err := DB.Create(&user).Error
252 AssertEqual(t, err, nil)
253}
254
255func TestBelongsToAssociationUnscoped(t *testing.T) {
256 type ItemParent struct {

Callers

nothing calls this directly

Calls 6

SessionMethod · 0.80
DropTableMethod · 0.65
MigratorMethod · 0.65
AutoMigrateMethod · 0.65
CreateMethod · 0.65
AssertEqualFunction · 0.50

Tested by

no test coverage detected