Joseph Palermo
2009-Jan-09 20:46 UTC
Bugs in eager loading of has_one :through and has_many :through
Failing test can be found here: http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1723-eager-load-of-has_one-through-with-conditions-on-the-through-table-fails Eager loading of has_one :through has an easy to fix problem. It doesn''t pass the :conditions or :order of the base association down to the "source" include on the :through association. has_many :through does this already, the "options" just need to be passed down. The larger problem, of both has_one :through and has_many :through is when you have a :conditions that references the :through table. Since preload never does any joining, it always does the associations independently, it throws a SQL error because it can''t find that table. This is only a problem with eager loading, the find_every code in base.rb does the correct detection normally. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2009-Jan-11 10:41 UTC
Re: Bugs in eager loading of has_one :through and has_many :through
On 9 Jan 2009, at 20:46, Joseph Palermo wrote:> > Failing test can be found here: > http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1723-eager-load-of-has_one-through-with-conditions-on-the-through-table-fails > > Eager loading of has_one :through has an easy to fix problem. It > doesn''t pass the :conditions or :order of the base association down to > the "source" include on the :through association. has_many :through > does this already, the "options" just need to be passed down. > > The larger problem, of both has_one :through and has_many :through is > when you have a :conditions that references the :through table. Since > preload never does any joining, it always does the associations > independently, it throws a SQL error because it can''t find that table. >I''ve been vaguely meaning to rewrite the preload code so that it loads hmt associations in one go (rather than loading the records in two steps). There''s a preliminary task which is to refactor the hmt code to make it easy for the preload stuff to recreate the appropriate joins (don''t really fancy duplicating all that like in join based eager loading). Fred> This is only a problem with eager loading, the find_every code in > base.rb does the correct detection normally. > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---