I''m trying to dynamically build up a complex search screen using named scopes very much like in ryans recent railscast at http://railscasts.com/episodes/112. I''m finding issue though that the second named scope is wiping out the joins in the first scope. For Example: scope = ProjectTotalView.scoped({}) scope = scope.scoped({ :joins => "INNER JOIN proj_funding_schemes_vw ON (proj_funding_schemes_vw.fin_project_id project_totals_vw.fin_project_id)", :conditions => "proj_funding_schemes_vw.currency_code in (''USD'',''AUD'')" }) scope = scope.scoped({ :joins => "INNER JOIN project_rfcds_vw ON (project_rfcds_vw.fin_project_id = project_totals_vw.fin_project_id)", :conditions => "project_rfcds_vw.rfcd_code in (''250400'')" }) scope.all If you swap the scopes around, it''s always the other one that says unknown column rfcd_code etc. It''s because it only does the first join that this error occurs. Any idea on how I can fix (if it is an issue) named_scope so it does combine the :joins instead. I''ve tried looking though /active_record/named_scope.rb and I can''t actually work out at the point where those conditions get added to the "sql builder" -- 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 -~----------~----~----~----~------~----~------~--~---
I''ve also found this is talked about here: http://www.ruby-forum.com/topic/154275 A ticket marked as incomplete on lighthouse: http://rails.lighthouseapp.com/projects/8994/tickets/46-named_scope-should-support-joins A simple fix for: http://blog.teksol.info/2008/5/26/why-are-activerecord-scopes-not-merged Alex Moore wrote:> I''m trying to dynamically build up a complex search screen using named > scopes very much like in ryans recent railscast at > http://railscasts.com/episodes/112. > > I''m finding issue though that the second named scope is wiping out the > joins in the first scope. > > For Example: > scope = ProjectTotalView.scoped({}) > > scope = scope.scoped({ > :joins => "INNER JOIN proj_funding_schemes_vw ON > (proj_funding_schemes_vw.fin_project_id > project_totals_vw.fin_project_id)", > :conditions => "proj_funding_schemes_vw.currency_code in > (''USD'',''AUD'')" > }) > > scope = scope.scoped({ > :joins => "INNER JOIN project_rfcds_vw ON > (project_rfcds_vw.fin_project_id = project_totals_vw.fin_project_id)", > :conditions => "project_rfcds_vw.rfcd_code in (''250400'')" > }) > > scope.all > > > If you swap the scopes around, it''s always the other one that says > unknown column rfcd_code etc. It''s because it only does the first join > that this error occurs. > > Any idea on how I can fix (if it is an issue) named_scope so it does > combine the :joins instead. I''ve tried looking though > /active_record/named_scope.rb and I can''t actually work out at the point > where those conditions get added to the "sql builder"-- 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 -~----------~----~----~----~------~----~------~--~---