Re: Order by date

Toby Boudreaux
Sun, 24 Jul 2005 15:41:01 -0000

If you don''t want to use the now() function, don''t -- use
Time.now or
something and pass it to the condition as a param.

I don''t think rdbms-specific sql is bad, though. Most of the time,
you have to address your particular RDBMS in order to optimize
queries. Phrasebooks are great for this purpose, and could certainly
be implemented in a Rails app.



On Jul 24, 2005, at 11:33 AM, Abdullah Jibaly wrote:

> Hi all,
>
> In Agile Web Dev w/Rails it is shown how to order a collection by
> date as:
>
> # Return a list of products we can sell (which means they have to be
> # available). Show the most recently available first.
> def self.salable_items
>   find(:all,
>        :conditions => "date_available <= now()",
>        :order      => "date_available desc")
> end
>
> What if I do not want to be tied to MySQL (the now function)? If I
> want to
> migrate to another db I''d have to change my source code, which is
> not good,
> right? What is a better alternative?
>
> Thanks,
> Abdullah