-
Notifications
You must be signed in to change notification settings - Fork 550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question passing an Int slice into WhereIn #227
Comments
The bottom one should be working, can you turn on debug mode and show what kind of query or error you're getting? Need more information to determine what the problem is :) |
I have had problems with this too. The solution is to convert your slice to Example ids := []int{1, 2, 3}
convertedIDs := make([]interface{}, len(ids))
for index, num := range ids {
convertedIDs[index] = num
}
qm.WhereIn("id IN ?", convertedIDs...) |
thank you it works |
I actually think we should try to fix this. It shouldn't really behave like this and we may be able to do something about it. |
This problem is from golang/go#16235 |
Unfortunately after looking into it, there is no way to be able to do this :( It's possible to use arrays in general as ceshihao is suggesting, but that requires driver support and is actually usable today without any changes. |
@aarondl I'm pretty sure we can fix this with a quick bit of reflection. Right now we always expect that a user splats their variadic arg. That's the root cause of the issue. For argument's sake, lets allow people to call WhereIn with a slice ( Then, we inspect our variadic argument to see if
We use reflect to see if the only item in I'll make a PR now |
Here's a quick demo: https://play.golang.org/p/0rrgz5cwFtj |
Still doesn't work unless you use something like this
|
how do I pass a slice into whereIn?
example
qm.WhereIn("id in ?", 1, 2, 3)
these won't work
The text was updated successfully, but these errors were encountered: