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

Function TestSelectWithUpdateColumn

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

Source from the content-addressed store, hash-verified

475}
476
477func TestSelectWithUpdateColumn(t *testing.T) {
478 user := *GetUser("select_with_update_column", Config{Account: true, Pets: 3, Toys: 3, Company: true, Manager: true, Team: 3, Languages: 3, Friends: 4})
479 DB.Create(&user)
480
481 updateValues := map[string]interface{}{"Name": "new_name", "Age": 50}
482
483 var result User
484 DB.First(&result, user.ID)
485
486 time.Sleep(time.Second)
487 lastUpdatedAt := result.UpdatedAt
488 DB.Model(&result).Select("Name").Updates(updateValues)
489
490 var result2 User
491 DB.First(&result2, user.ID)
492
493 if lastUpdatedAt.Format(time.RFC3339Nano) == result2.UpdatedAt.Format(time.RFC3339Nano) {
494 t.Errorf("UpdatedAt should be changed")
495 }
496
497 if result2.Name == user.Name || result2.Age != user.Age {
498 t.Errorf("Should only update users with name column")
499 }
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})

Callers

nothing calls this directly

Calls 6

GetUserFunction · 0.85
ModelMethod · 0.80
CreateMethod · 0.65
FirstMethod · 0.65
UpdatesMethod · 0.65
SelectMethod · 0.65

Tested by

no test coverage detected