Named Scope Woes

I'm trying to dynamically build up a complex search screen using named scopes very much like in ryans recent railscast at #112 Anonymous Scopes - RailsCasts.

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"

I've also found this is talked about here:

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: