Skip to content

Instantly share code, notes, and snippets.

@laurynas
Created November 26, 2010 10:00
Show Gist options
  • Save laurynas/716490 to your computer and use it in GitHub Desktop.
Save laurynas/716490 to your computer and use it in GitHub Desktop.
SearchLogic problem with left join in order SOLVED!
class Item < ActiveRecord::Base
named_scope :ascend_by_optional_category_title,
:joins => "LEFT JOIN categories AS optional_categories ON optional_categories.id=items.category_id",
:order => "optional_categories.title"
named_scope :descend_by_optional_category_title,
:joins => "LEFT JOIN categories AS optional_categories ON optional_categories.id=items.category_id",
:order => "optional_categories.title DESC"
end
Item.search( :order => :ascend_by_optional_category_title )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment