#66 ✓resolved
Simone Carletti

Searchlogic doesn't support AR nested conditions

Reported by Simone Carletti | March 10th, 2009 @ 07:14 AM

It seems Searchlogic doesn't support AR nested conditions. I have the following database schema

class Product < ActiveRecord::Base
  has_many :gateways, :dependent => :destroy
  has_many :partners, :through => :gateways

class Partner < ActiveRecord::Base
  has_many :gateways, :dependent => :destroy
  has_many :products, :through => :gateways
  # partner has a published boolean field

class Gateway < ActiveRecord::Base
  belongs_to :product
  belongs_to :partner

When I try to run a query with nested conditions, like the following one

Gateway.all(:joins => :partner, :conditions => { :partners => { :published => true }}, :order => 'position')

Searchlogic raises a NoMethodError

1) Error:
NoMethodError: undefined method `partners=' for #<GatewayConditions>
  /Library/Ruby/Gems/1.8/gems/searchlogic-1.6.4/lib/searchlogic/conditions/magic_methods.rb:185:in `method_missing'
  /Library/Ruby/Gems/1.8/gems/searchlogic-1.6.4/lib/searchlogic/active_record/base.rb:167:in `send'
  /Library/Ruby/Gems/1.8/gems/searchlogic-1.6.4/lib/searchlogic/active_record/base.rb:167:in `filter_options_with_searchlogic'
  /Library/Ruby/Gems/1.8/gems/searchlogic-1.6.4/lib/searchlogic/active_record/base.rb:167:in `each'
  /Library/Ruby/Gems/1.8/gems/searchlogic-1.6.4/lib/searchlogic/active_record/base.rb:167:in `filter_options_with_searchlogic'
  /Library/Ruby/Gems/1.8/gems/searchlogic-1.6.4/lib/searchlogic/active_record/base.rb:21:in `find'
  /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:609:in `all'
  /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/associations/association_collection.rb:370:in `send'
  /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/associations/association_collection.rb:370:in `method_missing'
  /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2003:in `with_scope_without_searchlogic'
  /Library/Ruby/Gems/1.8/gems/searchlogic-1.6.4/lib/searchlogic/active_record/base.rb:47:in `with_scope'
  /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/associations/association_proxy.rb:202:in `send'
  /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/associations/association_proxy.rb:202:in `with_scope'
  /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/associations/association_collection.rb:366:in `method_missing'

It doesn't matter whether the query takes advantage of Searchlogic features or not. As soon as I load the GEM all my queries are invalidated.

Comments and changes to this ticket

  • Ben Johnson

    Ben Johnson March 10th, 2009 @ 10:42 AM

    • State changed from “new” to “resolved”

    Nested conditions is the whole point of searchlogic, so it does support them. Partners is not a method, it is partner. Singular.

  • Simone Carletti

    Simone Carletti March 10th, 2009 @ 11:01 AM

    Hi Ben, thanks for your quick reply. However, passing the :partner option doesn't work.

    SQLite3::SQLException: no such column: partner.published: SELECT "gateways".* FROM "gateways"   INNER JOIN "partners" ON "partners".id = "gateways".partner_id  WHERE ("partner"."published" = 't') AND ("gateways".product_id = 76749056)  ORDER BY position

    You can find an other example here in this Ryan's post. http://ryandaigle.com/articles/2...

    The example uses :articles, not :article.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Provides common named scopes and object based searching.

People watching this ticket