Andrew Selder
2009-May-10 19:24 UTC
Problem with find with :joins and :include in same call
Hi all, I am investigating moving our app from Rails 2.2.2 to Rails 2.3.2. So far doesn''t look too bad, but I am running in to one problem. In a model I have the following named scope: named_scope :valid, {:include => :broker, :joins => ''INNER JOIN `payers` ON `payers`.customer_id = `brokers`.id AND `payers`.customer_type = \''Broker\'''', :conditions => "payers.status ''active'' and ticket_sets.delete_flag = 0 and ticket_sets.qty > 0 and (brokers.ei_id is NULL or (brokers.ei_id is not null and ticket_sets.ei_id is not null)) "} This worked perfectly in Rails 2.2.2, but in Rails 2.3.2 this blows up. Looking at the log file, it appears that the :include clause isn''t being parsed. SELECT `ticket_sets`.* FROM `ticket_sets` INNER JOIN `payers` ON `payers`.customer_id = `brokers`.id AND `payers`.customer_type ''Broker'' WHERE (payers.status = ''active'' and ticket_sets.delete_flag 0 and ticket_sets.qty > 0 and (brokers.ei_id is NULL or (brokers.ei_id is not null and ticket_sets.ei_id is not null)) ) If I remove the the joins clause, the brokers get included like they should be, but it doesn''t have payers referenced. One option would be into use nested includes to include the payers; but this has some serious performance issues. The ticket sets table is large and we don''t need to the payers data returned, just for selection. Does anybody have any ideas? Thanks, Andrew -- Posted via http://www.ruby-forum.com/.
Frederick Cheung
2009-May-10 19:31 UTC
Re: Problem with find with :joins and :include in same call
On May 10, 8:24 pm, Andrew Selder <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> One option would be into use nested includes to include the payers; but > this has some serious performance issues. The ticket sets table is large > and we don''t need to the payers data returned, just for selection. > > Does anybody have any ideas? >it looks like a bug in the code that determines which include strategy should be used Fred> Thanks, > > Andrew > -- > Posted viahttp://www.ruby-forum.com/.
Andrew Selder
2009-May-10 19:34 UTC
Re: Problem with find with :joins and :include in same call
Frederick Cheung wrote:> On May 10, 8:24�pm, Andrew Selder <rails-mailing-l...@andreas-s.net> > wrote: > >> One option would be into use nested includes to include the payers; but >> this has some serious performance issues. The ticket sets table is large >> and we don''t need to the payers data returned, just for selection. >> >> Does anybody have any ideas? >> > it looks like a bug in the code that determines which include strategy > should be used > > FredFred, Do you want me to file a bug at lighthouse? Thanks, Andrew -- Posted via http://www.ruby-forum.com/.
Andrew Selder
2009-May-10 19:48 UTC
Re: Problem with find with :joins and :include in same call
Filed at Lighthouse as #2631. -- Posted via http://www.ruby-forum.com/.
Lakshmi Narayana
2009-May-11 14:13 UTC
Re: Problem with find with :joins and :include in same call
i think only include or joins should be used not both.. On Mon, May 11, 2009 at 1:18 AM, Andrew Selder < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Filed at Lighthouse as #2631. > -- > 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2009-May-11 14:53 UTC
Re: Problem with find with :joins and :include in same call
On May 11, 3:13 pm, Lakshmi Narayana <lakshis...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> i think only include or joins should be used not both.. >in general, nothing wrong with using both (for distinct associations - wouldn''t want to include and join the same association) Fred> On Mon, May 11, 2009 at 1:18 AM, Andrew Selder < > > rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > Filed at Lighthouse as #2631. > > -- > > Posted viahttp://www.ruby-forum.com/.