searchlogic icon indicating copy to clipboard operation
searchlogic copied to clipboard

Multiple arguments breaks IN (?) support in forms

Open nicolasblanco opened this issue 15 years ago • 2 comments

Being able to pass multiple arguments is a great idea for custom named_scopes in the model but IMHO this feature should not be enabled by default on Searchlogic dynamic named_scopes.

I was using Searchlogic with my forms to pass multiple values in a Searchlogic _equals named_scope to create a IN (?) conditions, and since this commit, it is entirely broken.

>> User.state_equals(["refused", "banned", "aborted", "deleted"]).all
(This works!)

>> User.searchlogic(:state_equals => ["refused", "banned", "aborted", "deleted"]).all
/Library/Ruby/Gems/1.8/gems/searchlogic-2.3.9/lib/searchlogic/named_scopes/conditions.rb:117: warning: multiple values for a block parameter (4 for 1)
    from /Library/Ruby/Gems/1.8/gems/searchlogic-2.3.9/lib/searchlogic/named_scopes/conditions.rb:175
ActiveRecord::PreparedStatementInvalid: wrong number of bind variables (4 for 1) in: users.state IN (?)

nicolasblanco avatar Dec 18 '09 10:12 nicolasblanco

I am experiencing the same problem. Using a multi select to pass in possible values to search.

demersus avatar Oct 15 '10 17:10 demersus

You can define a scope inside your model as a work around.

class MyModel < ActiveRecord::Base
    scope_procedure :any_field_eq, lambda { |field_csv| field_eq field_csv.try(:split, ',') }
end

If params[:search][:any_field_eq] = "v1,v2,v3", then you can do User.search(params[:search])

khoan avatar Nov 03 '10 05:11 khoan