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

Function TestOrWithAllFields

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

Source from the content-addressed store, hash-verified

664}
665
666func TestOrWithAllFields(t *testing.T) {
667 dryDB := DB.Session(&gorm.Session{DryRun: true, QueryFields: true})
668 userQuery := "SELECT .*users.*id.*users.*created_at.*users.*updated_at.*users.*deleted_at.*users.*name" +
669 ".*users.*age.*users.*birthday.*users.*company_id.*users.*manager_id.*users.*active.* FROM .*users.* "
670
671 result := dryDB.Where("role = ?", "admin").Or("role = ?", "super_admin").Find(&User{})
672 if !regexp.MustCompile(userQuery + "WHERE .*role.* = .+ OR .*role.* = .+").MatchString(result.Statement.SQL.String()) {
673 t.Fatalf("Build OR condition, but got %v", result.Statement.SQL.String())
674 }
675
676 result = dryDB.Where("users.name = ?", "jinzhu").Or(User{Name: "jinzhu 2", Age: 18}).Find(&User{})
677 if !regexp.MustCompile(userQuery + "WHERE .*users.*name.* = .+ OR \\(.*users.*name.* AND .*users.*age.*\\)").MatchString(result.Statement.SQL.String()) {
678 t.Fatalf("Build OR condition, but got %v", result.Statement.SQL.String())
679 }
680
681 result = dryDB.Where("users.name = ?", "jinzhu").Or(map[string]interface{}{"name": "jinzhu 2", "age": 18}).Find(&User{})
682 if !regexp.MustCompile(userQuery + "WHERE .*users.*name.* = .+ OR \\(.*age.* AND .*name.*\\)").MatchString(result.Statement.SQL.String()) {
683 t.Fatalf("Build OR condition, but got %v", result.Statement.SQL.String())
684 }
685}
686
687type Int64 int64
688

Callers

nothing calls this directly

Calls 5

SessionMethod · 0.80
FindMethod · 0.65
OrMethod · 0.65
WhereMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected