views:

69

answers:

1

I have two models Employee & Unit. Unit has many Employees. I am using SearchLogic to search employee model. What is the equivalent of below SQL in Searchlogic

employees.unit_id IN (1,2,3)

I have tried both

unit_id_equals_all[] 
unit_id_equals_any[]

But nothing works. Can anyone help?

Thanks, Abhilash

A: 
Employee.unit_id_equals([1, 2, 3])
PeterWong
Unfortunately that does not work. I get this error "wrong number of bind variables (2 for 1) in: employees.unit_id IN (?)"
eabhvee
Could you give more hints about the error message? such as when is the message being generated? I can't get why there were 2 variables......
PeterWong
In my search view I selected 2 units and passed it as an array, if I select 5 it will say 5 for 1. My params hash is like this --> unit_id_equals"=>["332", "333"]
eabhvee
BTW, Employee.unit_id_equals([332,333]) works fine in the console
eabhvee
Yes this should work. Are you sure you are `...equals(["332", "333])` instead of `...equals("332", "333")`? The latter one give the same error message while the former one is correct and worked fine.
PeterWong
Thanks for the clarification. This is my view code <%= check_box_tag "search[unit_id_equals][]", unit.id %> Is there something wrong here?
eabhvee
Found the reason. This is an issue in searchlogic Employee.unit_id_equals([1, 2, 3]) works but Employee.search(:unit_id_equals => [1, 2, 3]).all does not work http://github.com/binarylogic/searchlogic/issues/issue/64
eabhvee