Forum: Ruby on Rails find() and SQL functions

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
28c315da59bc0bc0a544ed4a75ad26e9?d=identicon&s=25 Pierre-Alexandre Meyer (Guest)
on 2007-03-16 16:01
(Received via mailing list)

I have a complex SQL request to perform. I don't want to manually do the
whole query (find_by_sql) because of the complex joins, but I want to
use MySQL functions, such as:

           :include => [../..],
           :conditions => ["(../..) AND
YEAR(STR_TO_DATE(my_table.my_row,'%Y-%m-%d %H:%i:%s')) = #{year})"],
           :select => [../..])


           :include => [../..],
           :conditions => ["(../..) AND
           :select => [../..])

Is there a way to combine the power of AR and SQL functions?

In the example above, I could use Ruby Time Class but what can I do if I
want to use more specific SQL syntax (UNION, ...). I guess I have to
make the joins by hand with find_by_sql?

| Pierre-Alexandre Meyer |
| email : |
This topic is locked and can not be replied to.