> class WidgetController < ApplicationController
>   around_filter ScopedFilter.new(SiteWidget, {:find => {:include =>
> [:site_root], :condtions => 'site_root.site_id = X'}})
>
>   def show_widgets
>     @widgets = Widget.find :all, :include => [:some_other_relation]
>   end
> end

Get your site object in a before filter form the domain, then use its
has_many relationships to all your models.

>   def show_widgets
>     @widgets = Widget.find :all, :include => [:some_other_relation]
>   end

becomes

   def show_widgets
     @widgets = @site.widgets.find :all, :include => [:some_other_relation]
   end

if you need the variable scope you can alternatively do this:

   def show_widgets
     @widgets = scope.find :all, :include => [:some_other_relation]
   end

   def scope
      params[:global] ? Widget : @site.widgets
   end

Yes, you have to get the site object by a dedicated select and can't
eager load it in but by no stretch of imagination would that have any
considerable negative impact on your performance.




--
Tobi
http://shopify.com       - modern e-commerce software
http://typo.leetsoft.com - Open source weblog engine
http://blog.leetsoft.com - Technical weblog
_______________________________________________
Rails-core mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-core

Reply via email to