Adding School Condition

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?

I should mention putting …WHERE (verified > 5)… as it is in the
statement already returns an error about there being no verified column.

Try schools.verified > 5 instead.

On Dec 11, 2007 2:39 AM, Ellis B. [email protected]
wrote:

I should mention putting …WHERE (verified > 5)… as it is in the
statement already returns an error about there being no verified column.

Posted via http://www.ruby-forum.com/.


Ryan B.

Isn’t it verified_by? And because it’s serialised you’ll need to use
something else other than a WHERE MySQL call.

On Dec 11, 2007 9:54 AM, Ellis B. [email protected]
wrote:

LIMIT 3

Posted via http://www.ruby-forum.com/.


Ryan B.

Nope I use the column verified to track the integer count of how many
unique users (from my serialized user_ids field) have verified a school.

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

Ah, good idea.

Does that sql_query return schools as an array? Perhaps it would be
easier
to do a #select call on the returned array?

On Dec 11, 2007 10:25 AM, Ellis B.
[email protected]
wrote:

Nope I use the column verified to track the integer count of how many
unique users (from my serialized user_ids field) have verified a school.

Posted via http://www.ruby-forum.com/.


Ryan B.