mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
fix issue #1217
This commit is contained in:
@ -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,
|
||||
|
||||
@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user