Forked from anonymous/AAF Deep search in child record
Created
April 26, 2009 22:07
-
-
Save AndyMoreland/102191 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
### In main model | |
# for each Beer object, there are some number 0-50 individual review objects, listed | |
# in the Tastes model | |
# For my "beer list" in my view, i need to search the child reviews, looking for particular | |
# phrases and return the results | |
# | |
# Any suggestions? | |
### | |
class Beer < ActiveRecord::Base | |
belongs_to :brewery, :counter_cache => true | |
belongs_to :container | |
belongs_to :style | |
has_many :tastes | |
cattr_reader :per_page | |
@@per_page = 50 | |
def self.tastes_search | |
return nil if q.nil? or q=="" | |
default_options = {:limit => 24, :page => 1} | |
options = default_options.merge options | |
# get the offset based on what page we're on | |
options[:offset] = options[:limit] * (options.delete(:page).to_i-1) | |
# now do the query with our options | |
results = Taste.find_by_contents(q, options) | |
return [results.total_hits, results] | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment