Rails: Can joins join when binding regions?

In class A, I have two areas: s1 and s2, which both join through table T using the 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 this does not execute:

A.s1.s2.all

Mistake:

ActiveRecord :: StatementInvalid: Mysql :: Error: not unique table / alias: 'T'

I kind of expected Rails to be smart about those identical joins and just apply the join once, but it is not. I could use table aliases, but then I would have two more identical joins for no good reason.

I am sure there must be the right solution for this?

+3
source share
1 answer

, Rails 2.3.4:

ON JOIN, Rails , . -, JOIN.

:

+1

Source: https://habr.com/ru/post/1718989/


All Articles