Created
April 9, 2011 13:08
-
-
Save damian/911387 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Required for meta_search to use a named scope | |
search_methods :for_location, :at_location, :name_contains | |
scope :for_location, lambda { |location| location = Location.find(location) unless location.is_a?(Location); joins('LEFT OUTER JOIN administrators_locations ON administrators.id = administrator_id').where('location_id IN(?)', location.path_ids) } | |
scope :at_location, lambda { |location| location = Location.find(location) unless location.is_a?(Location); joins('INNER JOIN administrators_locations ON administrators.id = administrator_id').where('location_id = ?', location.id) } | |
scope :name_contains, lambda { |name| where("CONCAT_WS(' ', forename, surname) LIKE ?", "%#{name}%") } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment