Hello again, I am terrible with MySQL thanks to Rails, but here is an
instance to get the top_rated schools
def find_top_rated(limit=nil)
rating_class =
acts_as_rated_options[:rating_class].constantize
base_sql = <<-EOS
select #{table_name}.*,COALESCE(average,0) AS rating_average
from #{table_name} left outer join
(select avg(rating) as average, rated_id
from #{rating_class.table_name}
WHERE AND rated_type = ‘#{class_name}’
group by rated_id) as rated
on rated_id=id
order by rating_average DESC
EOS
base_sql += " LIMIT #{limit}" if limit
find_by_sql base_sql
end
How is it that I can add WHERE (verified > 5) so that I can restrict
what gets put in the array?
Mysql::Error: Unknown column ‘schools.verified’ in ‘where clause’:
select schools.*,COALESCE(average,0) AS rating_average from schools left
outer join
(select avg(rating) as average, rated_id
from ratings
where schools.verified > 5 AND rated_type = ‘School’
group by rated_id) as rated
on rated_id=id
order by rating_average DESC
LIMIT 3