On Thu, Apr 9, 2009 at 12:40 PM, Newb Newb
<rails-mailing-l...@andreas-s.net> wrote:
>
> Hi..
> how i should write the below query in rails.i found through mysql
> tutorial.i m not pro in rails ..so give some lights....
>
> SELECT * FROM contactinfo join userinfo on contactinfo.contact_id =
> userinfo.id where contactinfo.user_id = 25
>
> Thanks in advance

It would all depend on the models you're using.
That db schema is not technically Rails friendly in that the table
names should be user_infos and contact_infos resulting in models named
UserInfo and ContactInfo
Then you could use the following:

model ContactInfo
  has_one :user_info
  #or has_many :user_infos
end

model UserInfo
  belongs_to :contact_info
end

and then...

contact_info = ContactInfo.new 25
user_info = contact_info.user_info

Rails deals with all the sql in the background :-)

Andrew Timberlake
http://ramblingsonrails.com
http://www.linkedin.com/in/andrewtimberlake

"I have never let my schooling interfere with my education" - Mark Twain

--~--~---------~--~----~------------~-------~--~----~
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@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to