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

Function TestOmitWithUpdateColumn

tests/update_test.go:502–518  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

500}
501
502func TestOmitWithUpdateColumn(t *testing.T) {
503 user := *GetUser("omit_with_update_column", Config{Account: true, Pets: 3, Toys: 3, Company: true, Manager: true, Team: 3, Languages: 3, Friends: 4})
504 DB.Create(&user)
505
506 updateValues := map[string]interface{}{"Name": "new_name", "Age": 50}
507
508 var result User
509 DB.First(&result, user.ID)
510 DB.Model(&result).Omit("Name").UpdateColumns(updateValues)
511
512 var result2 User
513 DB.First(&result2, user.ID)
514
515 if result2.Name != user.Name || result2.Age == user.Age {
516 t.Errorf("Should only update users with name column")
517 }
518}
519
520func TestUpdateColumnsSkipsAssociations(t *testing.T) {
521 user := *GetUser("update_column_skips_association", Config{})

Callers

nothing calls this directly

Calls 6

GetUserFunction · 0.85
UpdateColumnsMethod · 0.80
ModelMethod · 0.80
CreateMethod · 0.65
FirstMethod · 0.65
OmitMethod · 0.65

Tested by

no test coverage detected