In a class A I have two scopes, s1 and s2 which both join over a table T using the exact same join columns:
named_scope :s1 :joins => "JOIN T on T.id = A.t_id", ...some conditions
named_scope :s2 :joins => "JOIN T on T.id = A.t_id", ...some other conditions
Now, doing this fails:
A.s1.s2.all
Error:
ActiveRecord::StatementInvalid: Mysql::Error: Not unique table/alias: 'T'
I sort of expected Rails to be smart about those identical joins, and simply apply the join once, but it doesn't. I could use table aliases, but then I'd still have two identical joins for no good reason.
I'm sure there must be a proper solution to this?