Skip to content

Commit

Permalink
Test query with Or and soft delete
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Feb 8, 2022
1 parent 93b1a6f commit 416c4d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ go 1.14
require (
github.com/denisenkom/go-mssqldb v0.12.0 // indirect
github.com/google/uuid v1.3.0
github.com/jackc/pgx/v4 v4.14.1 // indirect
github.com/jackc/pgx/v4 v4.15.0 // indirect
github.com/jinzhu/now v1.1.4
github.com/lib/pq v1.10.4
github.com/mattn/go-sqlite3 v1.14.11 // indirect
golang.org/x/crypto v0.0.0-20220128200615-198e4374d7ed // indirect
golang.org/x/crypto v0.0.0-20220208050332-20e1d8d225ab // indirect
gorm.io/driver/mysql v1.2.3
gorm.io/driver/postgres v1.2.3
gorm.io/driver/sqlite v1.2.6
Expand Down
8 changes: 7 additions & 1 deletion tests/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,13 @@ func TestNotWithAllFields(t *testing.T) {
func TestOr(t *testing.T) {
dryDB := DB.Session(&gorm.Session{DryRun: true})

result := dryDB.Where("role = ?", "admin").Where(DB.Or("role = ?", "super_admin")).Find(&User{})
var count int64
result := dryDB.Model(&User{}).Or("role = ?", "admin").Count(&count)
if !regexp.MustCompile("SELECT count\\(\\*\\) FROM .*users.* WHERE role = .+ AND .*users.*\\..*deleted_at.* IS NULL").MatchString(result.Statement.SQL.String()) {
t.Fatalf("Build OR condition, but got %v", result.Statement.SQL.String())
}

result = dryDB.Where("role = ?", "admin").Where(DB.Or("role = ?", "super_admin")).Find(&User{})
if !regexp.MustCompile("SELECT \\* FROM .*users.* WHERE .*role.* = .+ AND .*role.* = .+").MatchString(result.Statement.SQL.String()) {
t.Fatalf("Build OR condition, but got %v", result.Statement.SQL.String())
}
Expand Down

0 comments on commit 416c4d0

Please sign in to comment.