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

Function TestCreateWithAssociations

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

Source from the content-addressed store, hash-verified

157}
158
159func TestCreateWithAssociations(t *testing.T) {
160 user := *GetUser("create_with_associations", Config{
161 Account: true,
162 Pets: 2,
163 Toys: 3,
164 Company: true,
165 Manager: true,
166 Team: 4,
167 Languages: 3,
168 Friends: 1,
169 })
170
171 if err := DB.Create(&user).Error; err != nil {
172 t.Fatalf("errors happened when create: %v", err)
173 }
174
175 CheckUser(t, user, user)
176
177 var user2 User
178 DB.Preload("Account").Preload("Pets").Preload("Toys").Preload("Company").Preload("Manager").Preload("Team").Preload("Languages").Preload("Friends").Find(&user2, "id = ?", user.ID)
179 CheckUser(t, user2, user)
180}
181
182func TestBulkCreateWithAssociations(t *testing.T) {
183 users := []User{

Callers

nothing calls this directly

Calls 5

GetUserFunction · 0.85
CheckUserFunction · 0.85
CreateMethod · 0.65
FindMethod · 0.65
PreloadMethod · 0.65

Tested by

no test coverage detected