I have a SQL query that isn\'t table-specific and I don\'t know how to handle it with Ruby On Rails.
Here my SQL query (you don\'t need to understand it):
SELE
You can grab a db connection directly from ActiveRecord::Base, but it's not as useful as extending AR::Base, because helpful methods like sanitize_sql are protected.
class ComplexQueries < ActiveRecord::Base
def self.my_query
# Notice how you can, and should, still sanitize params here.
self.connection.execute(sanitize_sql(["select * from foo limit ?", 10]))
end
end
results = ComplexQueries.my_query
results.each_hash{|h| puts h.inspect}