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

Function TestOmit

tests/query_test.go:839–852  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

837}
838
839func TestOmit(t *testing.T) {
840 user := User{Name: "OmitUser1", Age: 20}
841 DB.Save(&user)
842
843 var result User
844 DB.Where("name = ?", user.Name).Omit("name").Find(&result)
845 if result.ID == 0 {
846 t.Errorf("Should not have ID because only selected name, %+v", result.ID)
847 }
848
849 if result.Name != "" || result.Age != 20 {
850 t.Errorf("User Name should be omitted, got %v, Age should be ok, got %v", result.Name, result.Age)
851 }
852}
853
854func TestOmitWithAllFields(t *testing.T) {
855 user := User{Name: "OmitUser1", Age: 20}

Callers

nothing calls this directly

Calls 4

SaveMethod · 0.80
FindMethod · 0.65
OmitMethod · 0.65
WhereMethod · 0.65

Tested by

no test coverage detected