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

Function TestFirstOrCreateWithPrimaryKey

tests/create_test.go:504–521  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

502}
503
504func TestFirstOrCreateWithPrimaryKey(t *testing.T) {
505 company := Company{ID: 100, Name: "company100_with_primarykey"}
506 DB.FirstOrCreate(&company)
507
508 if company.ID != 100 {
509 t.Errorf("invalid primary key after creating, got %v", company.ID)
510 }
511
512 companies := []Company{
513 {ID: 101, Name: "company101_with_primarykey"},
514 {ID: 102, Name: "company102_with_primarykey"},
515 }
516 DB.Create(&companies)
517
518 if companies[0].ID != 101 || companies[1].ID != 102 {
519 t.Errorf("invalid primary key after creating, got %v, %v", companies[0].ID, companies[1].ID)
520 }
521}
522
523func TestCreateFromSubQuery(t *testing.T) {
524 user := User{Name: "jinzhu"}

Callers

nothing calls this directly

Calls 2

FirstOrCreateMethod · 0.80
CreateMethod · 0.65

Tested by

no test coverage detected