ernie/squeel — Issue #83: Can't figure out how to order queries
Author: dukha
Created: 2011-11-25 05:05:51+00:00
State: open

I have a relatively simple 1 model query but I can't figure out how to get the ordering in. Closest that I have gotten is
courses = (Course.where{venue_id.in(accessible_venues.each{ |v| v.id} ) }).order{{course =>start_date.asc}}
Gave me an invalid sql statement in the console:

SELECT "courses".* FROM "courses" WHERE "courses"."venue_id" IN (88, 90, 91, 93, 95, 96, 99) ORDER BY "course"."start_date" ASC

The table name is courses so the logical thing to do is make courses plural in the order part:

courses = (Course.where{venue_id.in(accessible_venues.each{ |v| v.id} ) }).order{{courses =>start_date.asc}}

this gave
ArgumentError: Unable to get table for #
from /home/mark/.rvm/gems/ruby-1.9.2-p290/gems/squeel-0.9.3/lib/squeel/adapters/active_record/context.rb:59:in `get_table'

I'm obviously doing something stupid but there is no documentation that I could find on order{}.

Any help greatly appreciated

Regards

dukha
P.S. In the config file I have config.load_core_extensions :hash, :symbol