| 664 | } |
| 665 | |
| 666 | func 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 | |
| 687 | type Int64 int64 |
| 688 | |