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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Thu, Apr 9, 2009 at 12:40 PM, Newb Newb <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 advanceIt 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Newb Newb 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@contactinfo= Contactinfo.find(:all, :joins => "contactinfos inner join userinfos as u on contactinfos.contact_id=u.id", :conditions => ["contactinfos.contact_id =?", 25]) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Priya Buvan wrote:> Newb Newb 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 > > @contactinfo= Contactinfo.find(:all, :joins => "contactinfos inner join > userinfos as u on contactinfos.contact_id=u.id", :conditions => > ["contactinfos.contact_id =?", 25])Thanks for the reply.. using this query i can able to get only the contactinfo table fields but i want to get userinfo table fields as well as contactinfo fields also... how can i get that.. pls guide me on this -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Thu, Apr 9, 2009 at 3:14 PM, Newb Newb <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Priya Buvan wrote: >> Newb Newb 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 >> >> @contactinfo= Contactinfo.find(:all, :joins => "contactinfos inner join >> userinfos as u on contactinfos.contact_id=u.id", :conditions => >> ["contactinfos.contact_id =?", 25]) > > Thanks for the reply.. > using this query i can able to get only the contactinfo table fields but > i want to get userinfo table fields as well as contactinfo fields > also... > > how can i get that.. > pls guide me on this > --Don''t think of merging them into one result set, think of them as two seperate sets of data (or models) that are related. That''s the way Rails treats the data and it works very well. I understand that you''re new to Rails but take some time to get to understand Rails way of doing things and your life will be much easier. 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
i think this is the way you should write like this... as i am also new to rails ContactInfo.find(:all, :join => user_info) On Thu, Apr 9, 2009 at 4:10 PM, Newb Newb <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>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 > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You can use :select option in the same query.. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Priya Buvan wrote:> > You can use :select option in the same query..yes priya i used but i get error ...it gives me unknown column could you give the sample @contactinfo= ContactInfo.find(:all,:select => "userinfo.first_name,contactinfo.user_id", :joins => "contactinf inner join userinfo as u on contactinfo.contact_id=u.id", :conditions => ["contactinfo.user_id=?", 25]) pls help me ya Thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
why don''t you use the build options in the framework? specify the joins / relations in the model. Then do @user = User.find(params[:id]) (controller) View: <=% @user.contactinfo.telephone %> or <% for user in @users do |t| %> <%= t.contactinfo.telefone %> <%= t.contactinfo.fax %> If you cant to do other types of joins, use the include option in the controller. On Apr 10, 10:52 am, Newb Newb <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Priya Buvan wrote: > > > You can use :select option in the same query.. > > yes priya i used but i get error ...it gives me unknown column > > could you give the sample > > @contactinfo= ContactInfo.find(:all,:select => > "userinfo.first_name,contactinfo.user_id", :joins => "contactinf inner > join > userinfo as u on contactinfo.contact_id=u.id", :conditions => > ["contactinfo.user_id=?", 25]) > > pls help me ya > > Thanks > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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 For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---