-
-
Notifications
You must be signed in to change notification settings - Fork 804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid references to table aliases when joining multiple tables #1238
Comments
Is this similar/same as #1217 ? That issue is about table aliasing being broken under Rails 6.1 |
These two look pretty similar but with the difference that your issue references an alias that has not been defined but in my case the alias has been defined but is not being used. |
Thanks @yan-hoose you're right! I wonder if they're related in some way as in ours the problem is losing the table alias reference for the clause and in your case it creates an alias for the joins but then doesn't use it correctly. It is almost like there is some logic trying to de-dupe joins that is being done incorrectly and it effects your query at the join/gathering phase and effects ours in the clause phase. Hopefully either of these issues will see some attention :) |
This looks related to a Rails bug. |
Here is a fix that fixed the issues for us, but may re-introduce an eager load issue. |
Thanks Aaron! I'll check it out! |
I'm going to close this since #1217 is likely to have fixed this. Feel free to reopen if not though! |
First of all I'd like to thank the creators and maintainers of Ransack - it's been a valuable tool in many of my projects. Projects ranging from hobby stuff to big commercial applications. Thank you for your work!
Now, I ran into an issue where an invalid table alias is being used in the generated SQL. There are other issues currently open here that are similar but slightly different, that is why I created a new issue. In addition, many people reported here that their issue disappeared with an upgrade to Rails 6.1, but this issue persists with 6.1 too.
Consider this test case:
The resulting SQL is this:
As you can see line nr 4 of this SQL it references the table
users.id
, even though it should use the alias ofcreated_bies_tickets.id
.This results in an error message on PostgreSQL 13.3:
This invalid reference only happens when I add a manual
JOIN
to the result of Ransack query. Without the manualJOIN
, the query will be valid because it does not have to use a table alias:Versions which I tested and where this issue manifests:
Ruby: 2.6.7
Rails: 6.0.4, 6.1.4, 6-1-stable
Ransack: 2.4.2, master
PostgreSQL: 13.3
The text was updated successfully, but these errors were encountered: