Call Montréal, Canada 524-949-6869

Blog

Thursday, September 30, 2010

SearchLogic ordering not working: Uses associations default scope for ordering

Came across an interesting issue with Searchlogic. Given the following models:

class Organization < ActiveRecord::Base
  has_many :contacts
  default_scope :order => "name"
end

class Contact < ActiveRecord::Base
  belongs_to :association
end

Contact.search(:first_name_or_last_name_or_assocation_name => "Nicholas", :order => "descend_by_last_name")

The search will actually use the Organization default scope to order the search, i.e. by organization's "name", not contact's "last_name". The fix, unfortunately remove the default scope from the Organization class.

This appears to be an issue with ActiveRecord, not Searchlogic.

Developing Ruby on Rails applications and custom Content Management Systems in Montréal. Contact Firsthand.