This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sql = 'a big honking sql statement' | |
conditions = conditions_for_doodad | |
order = "#{params[:order_by]} #{params[:order]}" | |
Doodad.send(:add_conditions!, sql, conditions) | |
Doodad.send(:add_order!, sql, order) | |
@rs = ActiveRecord::Base.connection.select_all(sql) |
A few notes...When you call select_all you are returned an array of hashes with the column names as keys. If you call execute you will get an array of arrays and you will have to use column positions to index into the array (probably a bit faster than select_all on producing that record set). As of Rails 2.0 the record set that select_all returns can be used as the :collection parameter in a partial. Lastly, in addition to the :add_conditions! and :add_order! methods there is a very handy :construct_finder_sql as well which accepts the same options your would pass to a regular finder.