Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
activerecord: Duplicate aliases in generated query when combining `#joins()` and `#left_outer_joins()` with common join dependencies #30504
It's possible to generate queries with duplicate aliases when combining
Steps to reproduce
Considering the following schema:
Any of the following query will fail with ambiguous column (sqlite) or duplicate alias (postgresql):
The LEFT OUTER JOIN fragment of that query should alias the "posts" table and the resulting query should be executable.
Both joins are generated with their own alias tracker and end up either not using aliases (in this case) or could be using colliding aliases (if more joins where added by chaining additional associations in either the inner or left joins depending on "posts").
Rails version: 5.0.x, 5.1.x, 5.2.0-alpha
Ruby version: 2.3, 2.4
Nice! In the meantime, I'm using this workaround:
(basically, just hacking the alias manually)
Perhaps related. I have a scope that works in 4.2 and 5.0. It fails now very subtly. Very similar setup, the join references a has_many through the same table:
See the SQL bellow, identical but for the isolated line:
Join SQL in 4.2 and 5.0: (passes tests)
Join SQL in 5.1.3 (fails tests)
Rails version: 5.1.3
@zapo Got it. For what it's worth none of the models in my issue I'm using are STI.
Might be worth mentioning in my case that my example is using a double polymorphic join table (
I can open a new ticket if folks think its worthwhile, just let me know.