Re: SQL in rails

Andrew Bloom
Wed, 29 Oct 2008 14:06:25 -0000

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"}]

On Oct 29, 8:09 am, xxmithila
<xxmithil...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
> 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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com