| 837 | } |
| 838 | |
| 839 | func 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 | |
| 854 | func TestOmitWithAllFields(t *testing.T) { |
| 855 | user := User{Name: "OmitUser1", Age: 20} |