Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"testing"

"github.com/gobuffalo/uuid"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -48,6 +49,26 @@ func Test_Where_In(t *testing.T) {
})
}

func Test_Where_In_Slice(t *testing.T) {
r := require.New(t)
transaction(func(tx *Connection) {
u1 := &Song{Title: "A"}
u2 := &Song{Title: "A"}
u3 := &Song{Title: "A"}
err := tx.Create(u1)
r.NoError(err)
err = tx.Create(u2)
r.NoError(err)
err = tx.Create(u3)
r.NoError(err)

songs := []Song{}
err = tx.Where("id in (?)", []uuid.UUID{u1.ID, u3.ID}).Where("title = ?", "A").All(&songs)
r.NoError(err)
r.Len(songs, 2)
})
}

func Test_Where_In_Complex(t *testing.T) {
r := require.New(t)
transaction(func(tx *Connection) {
Expand Down
3 changes: 2 additions & 1 deletion sql_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ func (sq *sqlBuilder) compile() {
}

if inRegex.MatchString(sq.sql) {
s, _, err := sqlx.In(sq.sql, sq.Args())
s, args, err := sqlx.In(sq.sql, sq.Args()...)
if err == nil {
sq.sql = s
sq.args = args
}
}
sq.sql = sq.Query.Connection.Dialect.TranslateSQL(sq.sql)
Expand Down