mirror of https://github.com/go-gorm/gorm.git
Test query with Or and soft delete
This commit is contained in:
parent
93b1a6f7ea
commit
416c4d0653
|
@ -5,11 +5,11 @@ go 1.14
|
||||||
require (
|
require (
|
||||||
github.com/denisenkom/go-mssqldb v0.12.0 // indirect
|
github.com/denisenkom/go-mssqldb v0.12.0 // indirect
|
||||||
github.com/google/uuid v1.3.0
|
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/jinzhu/now v1.1.4
|
||||||
github.com/lib/pq v1.10.4
|
github.com/lib/pq v1.10.4
|
||||||
github.com/mattn/go-sqlite3 v1.14.11 // indirect
|
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/mysql v1.2.3
|
||||||
gorm.io/driver/postgres v1.2.3
|
gorm.io/driver/postgres v1.2.3
|
||||||
gorm.io/driver/sqlite v1.2.6
|
gorm.io/driver/sqlite v1.2.6
|
||||||
|
|
|
@ -512,7 +512,13 @@ func TestNotWithAllFields(t *testing.T) {
|
||||||
func TestOr(t *testing.T) {
|
func TestOr(t *testing.T) {
|
||||||
dryDB := DB.Session(&gorm.Session{DryRun: true})
|
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()) {
|
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())
|
t.Fatalf("Build OR condition, but got %v", result.Statement.SQL.String())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue