order of rules when using includes

9 views
Skip to first unread message

Brad Langhorst

unread,
Apr 30, 2012, 5:26:20 PM4/30/12
to declarative_...@googlegroups.com
Take the example of an admin user vs. a guest user.

for the guest i have the rule:

    has_permission_on :conditions, :to => [:new, :create,:update,:read,:show,:index] do
      if_permitted_to :read, :experimental_conditions
    end

    has_permission_on :experimental_conditions, :to => [:new, :create,:update,:read, :show, :index] do
      if_attribute :well_id => is { nil }
    end

but for the admin user i have the rule 

    has_permission_on :conditions, :to => [:new, :create,:update,:read,:show,:index]

(much less expensive)

the admin user also 
 includes [:guest]

so when i say
Conditions.with_permissions_to(:read) i always get the expensive left outer join performed. 
I have tried to change the position of the the includes hoping that the cheap rules will be evaluated first, but it does not seem to be the case.

What's the best way to handle this?

Brad
Reply all
Reply to author
Forward
0 new messages