Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

HABTM relationship queries fail with "undefined method" errors #165

Open
paulschreiber opened this issue Oct 27, 2013 · 0 comments
Open

Comments

@paulschreiber
Copy link

In SearchLogic 2.5.9 or greater, HABTM relationship queries fail with "undefined method" errors.

undefined method `bar_id_equals_any' for #<Class:0x7febd2642d30>
/home/myapp/shared/bundle/ruby/1.8/gems/searchlogic-2.5.14/
lib/searchlogic/named_scopes/column_conditions.rb:81:in `method_missing'

The cause of this is the change from respond_to? to respond_to_missing? in 16e7e26.

This may work in Ruby 1.9+, but fails in 1.8.7 (with Rails 2.3.18).

Example

class Foo
  has_and_belongs_to_many :bars
end
class Bar
  has_and_belongs_to_many :foos
end

Foo.bars_id_in(2)    # fails

I worked around this by monkey patching:

module Searchlogic
  module NamedScopes
    module ColumnConditions

      # In SearchLogic 2.5.9+, this was changed to respond_to_missing?
      # which breaks Foo.bar_id_equals_any(...) where Foo habtm Bar
      def respond_to?(*args)
        super || (self != ::ActiveRecord::Base && !self.abstract_class? && !create_condition(args.first).blank?)
      end

    end
  end
end
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant