This commit is contained in:
John Guo
2022-02-17 22:42:33 +08:00
parent b6a7788240
commit 17d7c92b9d
2 changed files with 16 additions and 20 deletions

View File

@ -374,13 +374,11 @@ func formatWhereHolder(db DB, in formatWhereHolderInput) (newWhere string, newAr
case reflect.Map:
for key, value := range DataToMapDeep(in.Where) {
if gregex.IsMatchString(regularFieldNameRegPattern, key) {
if in.OmitNil && empty.IsNil(value) {
continue
}
if in.OmitEmpty && empty.IsEmpty(value) {
continue
}
if in.OmitNil && empty.IsNil(value) {
continue
}
if in.OmitEmpty && empty.IsEmpty(value) {
continue
}
newArgs = formatWhereKeyValue(formatWhereKeyValueInput{
Db: db,
@ -406,13 +404,11 @@ func formatWhereHolder(db DB, in formatWhereHolderInput) (newWhere string, newAr
if iterator, ok := in.Where.(iIterator); ok {
iterator.Iterator(func(key, value interface{}) bool {
ketStr := gconv.String(key)
if gregex.IsMatchString(regularFieldNameRegPattern, ketStr) {
if in.OmitNil && empty.IsNil(value) {
return true
}
if in.OmitEmpty && empty.IsEmpty(value) {
return true
}
if in.OmitNil && empty.IsNil(value) {
return true
}
if in.OmitEmpty && empty.IsEmpty(value) {
return true
}
newArgs = formatWhereKeyValue(formatWhereKeyValueInput{
Db: db,

View File

@ -1454,7 +1454,7 @@ func Test_Model_Where_ISNULL_2(t *testing.T) {
"create_time > 0": nil,
"id": g.Slice{1, 2, 3},
}
result, err := db.Model(table).WherePri(conditions).Order("id asc").All()
result, err := db.Model(table).Where(conditions).Order("id asc").All()
t.AssertNil(err)
t.Assert(len(result), 3)
t.Assert(result[0]["id"].Int(), 1)
@ -1468,19 +1468,19 @@ func Test_Model_Where_OmitEmpty(t *testing.T) {
conditions := g.Map{
"id < 4": "",
}
result, err := db.Model(table).WherePri(conditions).Order("id asc").All()
result, err := db.Model(table).Where(conditions).Order("id desc").All()
t.AssertNil(err)
t.Assert(len(result), 3)
t.Assert(result[0]["id"].Int(), 1)
t.Assert(result[0]["id"].Int(), 3)
})
gtest.C(t, func(t *gtest.T) {
conditions := g.Map{
"id < 4": "",
}
result, err := db.Model(table).WherePri(conditions).OmitEmpty().Order("id asc").All()
result, err := db.Model(table).Where(conditions).OmitEmpty().Order("id desc").All()
t.AssertNil(err)
t.Assert(len(result), 3)
t.Assert(result[0]["id"].Int(), 1)
t.Assert(len(result), 10)
t.Assert(result[0]["id"].Int(), 10)
})
}