From 416c4d0653ce6e0569e6c868963a6c3cc769c2fb Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Tue, 8 Feb 2022 16:31:24 +0800 Subject: [PATCH] Test query with Or and soft delete --- tests/go.mod | 4 ++-- tests/query_test.go | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/go.mod b/tests/go.mod index f2addaa1..5488c17e 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -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 diff --git a/tests/query_test.go b/tests/query_test.go index c99214b6..d10df180 100644 --- a/tests/query_test.go +++ b/tests/query_test.go @@ -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()) }