Thanks Philip,
That's exactly what I did (before checking the forum). Actually There
were 2 problems:
1- ordering by name failed because I didn't have the LOWER(dealers.name)
field setup
2- ordering by launch date failed because the LOWER keyword doesn't
apply to dates (timestamps) but to strings only
So, to solve this issue, I've changed the :keyword named scope
before ---> :select => "DISTINCT dealers.*"
after ----> :select => "DISTINCT LOWER(dealers.name), dealers.*"
and added 2 named scopes for ordering, depending on which attribute has
been previously selected
named_scope :order_by_name, lambda {|direction| {:order =>
"LOWER(dealers.name) #{direction}, dealers.status_id #{direction},
dealers.established #{direction}"} }
named_scope :order_by_date, lambda {|direction| {:order =>
"dealers.launched_at #{direction}, dealers.status_id #{direction},
dealers.established #{direction}"} }
Now the query knows what to select and put it in order (lowercase dealer
names) as well as to avoid type collision (string vs datetime).
I'm currently looking into functional indexes, thanks for the tip!
Gabriella
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.