Skip to content
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

ORM creates wrong sql-query if ids is kind of Set #30684

Closed
mr-dxdy opened this issue Sep 22, 2017 · 3 comments
Closed

ORM creates wrong sql-query if ids is kind of Set #30684

mr-dxdy opened this issue Sep 22, 2017 · 3 comments

Comments

@mr-dxdy
Copy link

mr-dxdy commented Sep 22, 2017

Hi!

Rails: 4.2.7
Ruby: 2.2.4

User.where(id: Set.new([1, 2])).to_sql
=> "SELECT \"users\".* FROM \"users\" WHERE \"users\".\"id\" = NULL"

User.where(id: [1, 2]).to_sql
=> "SELECT \"users\".* FROM \"users\" WHERE \"users\".\"id\" IN (1, 2)"
@mr-dxdy mr-dxdy changed the title ORM creates invalid sql-query if ids is kind of Set ORM creates wrong sql-query if ids is kind of Set Sep 22, 2017
@al2o3cr
Copy link
Contributor

al2o3cr commented Sep 22, 2017

Short-term fix: use to_a on the Set before handing it to where.

Longer-term, seems like there would need to be a PredicateBuilder handler for Set.

@ccasabona
Copy link

It works if the Set is converted to an array:

User.where(id: Set.new([1, 2]).to_a).to_sql
"SELECT \"users\".* FROM \"users\" WHERE \"users\".\"id\" IN (1, 2)"

@michaldarda
Copy link

@sgrif sgrif closed this as completed in 9cf7e34 Sep 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants