binarylogic / searchlogic

Searchlogic provides object based searching, common named scopes, and other useful tools.
http://rdoc.info/projects/binarylogic/searchlogic
MIT License
1.39k stars 134 forks source link

Passing arrays to *_equals named scopes doesn't work in .search() #64

Open dtrasbo opened 14 years ago

dtrasbo commented 14 years ago

Basically, this works:

    >> Article.category_id_equals([1, 2])
    => [#<Article id: 1 ...>, #<Article id: 2 ...>, #<Article id: 3 ...>]

But this doesn't:

    >> Article.search(:category_id_equals => [1, 2]).all
    /usr/lib/ruby/gems/1.8/gems/searchlogic-2.4.10/lib/searchlogic/named_scopes/conditions.rb:115: warning: multiple values for a block parameter (2 for 1)
        from /usr/lib/ruby/gems/1.8/gems/searchlogic-2.4.10/lib/searchlogic/named_scopes/conditions.rb:173
    ActiveRecord::PreparedStatementInvalid: wrong number of bind variables (2 for 1) in: articles.category_id IN (?)

Here's the full stack trace:

from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2398:in `raise_if_bind_arity_mismatch'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2350:in `replace_bind_variables'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2341:in `sanitize_sql_array'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2230:in `sanitize_sql'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:1494:in `merge_conditions'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:1492:in `each'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:1492:in `merge_conditions'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:1804:in `add_conditions!'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:1687:in `construct_finder_sql'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:1548:in `find_every'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:615:in `find'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:635:in `all'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:181:in `send'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:181:in `method_missing'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2143:in `with_scope'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:113:in `__send__'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:113:in `with_scope'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:174:in `method_missing'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:181:in `send'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:181:in `method_missing'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2143:in `with_scope'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:113:in `__send__'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:113:in `with_scope'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:113:in `__send__'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:113:in `with_scope'
from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/named_scope.rb:174:in `method_missing'
from /usr/lib/ruby/gems/1.8/gems/searchlogic-2.4.10/lib/searchlogic/search.rb:123:in `send'
from /usr/lib/ruby/gems/1.8/gems/searchlogic-2.4.10/lib/searchlogic/search.rb:123:in `method_missing'
bjensen commented 14 years ago

Still a problem with the current version

graywh commented 14 years ago

This is a duplicate of issue #57.