Module: RatingFor::SingletonMethods

Defined in:
lib/rating_for.rb

Instance Method Summary collapse

Instance Method Details

#find_rated_by(element, rater) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/rating_for.rb', line 76

def find_rated_by(element, rater)
  found_objects = []
  Rating.find(:all, :conditions => "rater_id = #{rater.id} AND rater_type = \"#{rater.class}\" AND element_attribute = \"#{element}\"", :joins => [:rateable_element]).each do |rating|
    found_objects << find(:first, :conditions => {:id => rating.rateable_element.element_id})
  end
  found_objects.compact
end

#find_with_average_rating_of(element, value) ⇒ Object

TODO Check if this is DB-agnostic



61
62
63
64
# File 'lib/rating_for.rb', line 61

def find_with_average_rating_of(element, value)
  find :all, :conditions => "rateable_elements.element_attribute = \"#{element}\" AND rateable_elements.avg_rating = \"#{value}\"", 
       :joins => "INNER JOIN rateable_elements ON rateable_elements.element_id = #{self.name.underscore.pluralize}.id"
end

#find_with_ratings_count_of(element, value) ⇒ Object



71
72
73
74
# File 'lib/rating_for.rb', line 71

def find_with_ratings_count_of(element, value)
  find :all, :conditions => "rateable_elements.element_attribute = \"#{element}\" AND rateable_elements.ratings_count = \"#{value}\"", 
       :joins => "INNER JOIN rateable_elements ON rateable_elements.element_id = #{self.name.underscore.pluralize}.id"
end

#find_with_total_rating_of(element, value) ⇒ Object



66
67
68
69
# File 'lib/rating_for.rb', line 66

def find_with_total_rating_of(element, value)
  find :all, :conditions => "rateable_elements.element_attribute = \"#{element}\" AND rateable_elements.total_rating = \"#{value}\"", 
       :joins => "INNER JOIN rateable_elements ON rateable_elements.element_id = #{self.name.underscore.pluralize}.id"
end