Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.

Commit

Permalink
fix bug when query map condtion with no quote (#1449)
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny authored Oct 5, 2019
1 parent 6a47ef9 commit 57a49c6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
25 changes: 25 additions & 0 deletions session_get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,3 +618,28 @@ func TestCustomTypes(t *testing.T) {
assert.True(t, has)
assert.EqualValues(t, 32, age)
}

func TestGetViaMapCond(t *testing.T) {
type GetViaMapCond struct {
Id int64
Platform int
Index int
}

assert.NoError(t, prepareEngine())
assertSync(t, new(GetViaMapCond))

var (
r GetViaMapCond
platformStr = colMapper.Obj2Table("Platform")
indexStr = colMapper.Obj2Table("Index")
query = map[string]interface{}{
platformStr: 1,
indexStr: 1,
}
)

has, err := testEngine.Where(query).Get(&r)
assert.NoError(t, err)
assert.False(t, has)
}
8 changes: 6 additions & 2 deletions statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,12 @@ func (statement *Statement) And(query interface{}, args ...interface{}) *Stateme
cond := builder.Expr(query.(string), args...)
statement.cond = statement.cond.And(cond)
case map[string]interface{}:
cond := builder.Eq(query.(map[string]interface{}))
statement.cond = statement.cond.And(cond)
queryMap := query.(map[string]interface{})
newMap := make(map[string]interface{})
for k, v := range queryMap {
newMap[statement.Engine.Quote(k)] = v
}
statement.cond = statement.cond.And(builder.Eq(newMap))
case builder.Cond:
cond := query.(builder.Cond)
statement.cond = statement.cond.And(cond)
Expand Down

0 comments on commit 57a49c6

Please sign in to comment.