Dmitry Hazin
2006-Aug-23 11:20 UTC
[Rails] Decrease SELECT queries count; has_[joined_table_name]?
I execute a query with several :includes in it. For example, let''s say I use test = ModelClassName.find( id, :include => [ :table_1, :table_2 ]) Now test has methods called has_table_1? and has_table_2? If joined table_1 is not nil for this result (i.e. test.has_table_1? == true) I can simply get all attributes of table_1 using test.table_1.[attribute_name] and this wouldn''t cause additional databse query; But if test.has_table_1? == false, or, the same, test.table_1 == nil; calling of this methods (has_table_1? or test.table_1 == nil) creates additional query: SELECT * FROM table_1 WHERE (table_1.id = ...) So the question is: how to change this behaviour to avoid additional query? 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 -~----------~----~----~----~------~----~------~--~---
Jonathan Viney
2006-Aug-23 12:04 UTC
[Rails] Re: Decrease SELECT queries count; has_[joined_table_name]?
Caching of nil has_one associations has recently been added to trunk and will be in 1.2. You can run edge if you want to try it out. -Jonathan. On 8/23/06, Dmitry Hazin <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > I execute a query with several :includes in it. > For example, let''s say I use > > test = ModelClassName.find( id, :include => [ :table_1, :table_2 ]) > > Now test has methods called has_table_1? and has_table_2? > > If joined table_1 is not nil for this result (i.e. test.has_table_1? => true) > I can simply get all attributes of table_1 using > test.table_1.[attribute_name] > and this wouldn''t cause additional databse query; > > But if test.has_table_1? == false, or, the same, test.table_1 == nil; > calling of this methods (has_table_1? or test.table_1 == nil) creates > additional query: SELECT * FROM table_1 WHERE (table_1.id = ...) > > So the question is: how to change this behaviour to avoid additional > query? > > 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 -~----------~----~----~----~------~----~------~--~---
Dmitry Hazin
2006-Aug-23 12:30 UTC
[Rails] Re: Decrease SELECT queries count; has_[joined_table_name]?
Jonathan Viney wrote:> Caching of nil has_one associations has recently been added to trunk and > will be in 1.2. You can run edge if you want to try it out. > > -Jonathan.And what is the supposed date of 1.2 release? -- 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 -~----------~----~----~----~------~----~------~--~---
Dmitry Hazin
2006-Aug-23 12:58 UTC
[Rails] Re: Decrease SELECT queries count; has_[joined_table_name]?
Also what about caching of nil belong_to associations? Dmitry Hazin wrote:> Jonathan Viney wrote: >> Caching of nil has_one associations has recently been added to trunk and >> will be in 1.2. You can run edge if you want to try it out. >> >> -Jonathan. > > And what is the supposed date of 1.2 release?-- 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 -~----------~----~----~----~------~----~------~--~---