Method: ActsRateable::Count.get_totals

Defined in:
lib/acts_rateable/count.rb

.get_totals(author) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/acts_rateable/count.rb', line 15

def self.get_totals(author)
  sql = "SELECT COUNT(*) total_ratings, SUM(value) rating_sum, AVG(value) rating_avg, "+
        "(SELECT COUNT(DISTINCT author_id) FROM ar_rates WHERE author_type = '#{author.class.base_class.name}') rated_count, "+
        "((SELECT COUNT(*) from ar_rates WHERE author_type = '#{author.class.base_class.name}') / (SELECT COUNT(DISTINCT author_id) FROM ar_rates WHERE author_type = '#{author.class.base_class.name}')) avg_num_ratings "+
        "FROM ar_rates WHERE author_type = '#{author.class.base_class.name}'"
  #  RETURNS = { "total_ratings"=>"", "rating_sum"=>"", "rating_avg"=>"", "rated_count"=>"", "avg_num_ratings"=>"" }
  ActsRateable::Rate.connection.execute(sql).first
end