How do you make a direct connection to a db, not through the model? Can I make use of execute "SELECT...."? Can that be put into a variable? Not sure I''m thinking right here, but what if I want to fetch data connected to a user from many tables, say 10, should I use relations or is it smarter to fetch from each one separately? -- 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 -~----------~----~----~----~------~----~------~--~---
Pål Bergström wrote:> How do you make a direct connection to a db, not through the model? > > Can I make use of execute "SELECT...."? Can that be put into a variable? > > Not sure I''m thinking right here, but what if I want to fetch data > connected to a user from many tables, say 10, should I use relations or > is it smarter to fetch from each one separately?Hi Pål, Yes it is possible to connect directly to the db. You could create your own custom model, like my_db.rb (accessed via MyDb.find etc) or you could use one of your existing models and just use Model.find_by_sql("SELECT ....") or Model.find_by_sql(["SELECT.....", param1, param2, paramN...]). Using the last way, it''s possible to join those 10 tables of yours in 1 select statement. Hope that helps :) -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Look at the :include option in find. Rails can do your joins for you automatically. On Aug 23, 2006, at 12:28 AM, Pål Bergström wrote:> > How do you make a direct connection to a db, not through the model? > > Can I make use of execute "SELECT...."? Can that be put into a > variable? > > Not sure I''m thinking right here, but what if I want to fetch data > connected to a user from many tables, say 10, should I use > relations or > is it smarter to fetch from each one separately? > > -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Tom Mornini wrote:> Look at the :include option in find. Rails can do your joins for you > automatically. > > On Aug 23, 2006, at 12:28 AM, P�l Bergstr�m wrote:Is that as fast as doing a Model.find_by_sql("SELECT ....")? -- 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On Aug 23, 2006, at 5:34 AM, Pål Bergström wrote:> Tom Mornini wrote: >> Look at the :include option in find. Rails can do your joins for you >> automatically. >> >> On Aug 23, 2006, at 12:28 AM, P�l Bergstr�m wrote: > > Is that as fast as doing a Model.find_by_sql("SELECT ....")?It''s actually *faster* to write the code using the :include option, IMHO. :-) -- -- Tom Mornini --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---