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

id column not receiving array for custom ransacker #472

Closed
johnrees opened this issue Nov 24, 2014 · 5 comments
Closed

id column not receiving array for custom ransacker #472

johnrees opened this issue Nov 24, 2014 · 5 comments

Comments

@johnrees
Copy link

I have a ransacker called :student_users and use the filter student_users_in

I've simplified the code below to try and show what is happening

ransacker :student_users, :formatter => proc { |v|
  [10,11]
} do |parent|
  parent.table[:id]
end
...
SELECT DISTINCT "users".* FROM "users" WHERE "users"."id" IN (NULL)

I'd expect the above to return SELECT DISTINCT "users".* FROM "users" WHERE "users"."id" IN (10,11)

If I return an integer in the proc then it behaves as I'd expect

ransacker :student_users, :formatter => proc { |v|
  10
} do |parent|
  parent.table[:id]
end
...
SELECT DISTINCT "users".* FROM "users" WHERE "users"."id" IN (10)

If I filter the first_name (string) field instead of id, it shows that the array is actually getting passed from the proc

ransacker :student_users, :formatter => proc { |v|
  [10,11]
} do |parent|
  parent.table[:first_name]
end
...
SELECT DISTINCT "users".* FROM "users" WHERE "users"."first_name" IN ('---
- 10
- 11
')

Have I misunderstood something here?

@ideanl
Copy link
Contributor

ideanl commented Jan 3, 2015

I am experiencing the same issue, and have looked through the source a bit, but I'll keep digging for the bug. It appears that the first name is being passed in incorrectly, so that's also an issue right? I feel like this is a result of Arel updating to 6.0.

@jonatack
Copy link
Contributor

jonatack commented Jan 3, 2015

@johnrees, @ideanl, thanks for the issue. The first step would be to contribute a test for the problem. A test helps others reproduce the issue easily and work efficiently to solve it.

@jonatack
Copy link
Contributor

jonatack commented Jan 4, 2015

Update: #486 fixes compatibility with Arel 6.0. Filtering on a string field instead of id as per the OP's last example is still not working.

@ideanl
Copy link
Contributor

ideanl commented Jan 5, 2015

Filtering on a string field works now in PR #488

@jonatack
Copy link
Contributor

jonatack commented Jan 5, 2015

Great job! Closing this.

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

3 participants