SQL in rails


#1

Hi all…

please give me an example that use SQL in models to handel data in
the data base. with “sql.execute” or any other possible way…

thankx


#2

class Model < ActiveRecord::Base
def raw_sql_query
connection.execute(“select name from #{table_name}”)
end
end

The above example will return something like this:
[{:name => “A”}, {:name => “B”}]


#3

thankx Andrew
I’ll try it