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}'"
ActsRateable::Rate.connection.execute(sql).first
end
|