Hi forum! Please have a look at this link first: http://www.odamoz.org.mz/reports/rpt_own.asp I''m currently trying to refactor that in Rails, here''s some more info first: - We are looking for Projects. - A project has_and_belongs_to_many MDGs, Donors, Provinces and Sectors. My initial idea would lead to a horrible performance, so any other ideas are appreciated. Here is it, though: - Get all projects for each of the selected items - Join and unify the result arrays using the & operator. [code=]mdg_prj = MDG.find(params[:mdgs]).projects donor_prj = Donor.find(params[:donors]).projects province_prj = Province.find(params[:provinces]).projects sector_prj = DacSector.find(params[:sectors]).projects prj_result = mdg_prj & donor_prj & province_prj & sector_prj[/code] Image this with >10000 projects.. :( Does anyone of you have any idea? That''s really driving me nuts. Regards, Pascal -- 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 27 Nov 2007, at 16:57, Pascal Ehlert wrote:> > Hi forum! > > Please have a look at this link first: > http://www.odamoz.org.mz/reports/rpt_own.asp > > I''m currently trying to refactor that in Rails, here''s some more info > first: > - We are looking for Projects. > - A project has_and_belongs_to_many MDGs, Donors, Provinces and > Sectors. >If you write out the joins, you''ll get 8 joins (1 for the join table and one for the actual table). That''s a fair few joins, but not the end of the world, and databases are likely to be better at doing this sort of thing than ruby. In mysql if join optimiser is getting it wrong you can force the ordering you supply Fred> My initial idea would lead to a horrible performance, so any other > ideas > are appreciated. > Here is it, though: > - Get all projects for each of the selected items > - Join and unify the result arrays using the & operator. > [code=]mdg_prj = MDG.find(params[:mdgs]).projects > donor_prj = Donor.find(params[:donors]).projects > province_prj = Province.find(params[:provinces]).projects > sector_prj = DacSector.find(params[:sectors]).projects > > prj_result = mdg_prj & donor_prj & province_prj & sector_prj[/code] > Image this with >10000 projects.. :( > > > Does anyone of you have any idea? That''s really driving me nuts. > > > Regards, > > Pascal > -- > 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 Nov 27, 11:05 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 27 Nov 2007, at 16:57, Pascal Ehlert wrote: > > > > > Hi forum! > > > Please have a look at this link first: > >http://www.odamoz.org.mz/reports/rpt_own.asp > > If you write out the joins, you''ll get 8 joins (1 for the join table > and one for the actual table).... > ... databases > are likely to be better at doing this sort of thing than ruby.I agree. I would just call find_by_sql in this case. I find that a bit clearer than calling find with :joins. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---