-
-
Notifications
You must be signed in to change notification settings - Fork 809
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
Cannot join same table multiple times in new version #1144
Comments
That's a pretty extreme query! |
This might be the same issue as #1151 ? |
I am experiencing the same issue Is there a workaround for this? It would be much appreciated. |
@sebaas It works for me in version 2.3.2 :-) |
@kaspernj The 2.3.2 and the 2.40 both fail. It fails, both, by not calling the correct table name when a the same table is joined twice, the first join has not an alias but the alias it is written in the where clause of the query, while the second join has the alias and it is well referenced by the where clause built in the query. Again if I switch the order of the params, the first join name get "guessed" wrong. |
Here is another one. Notice in the last join it suddenly starts calling "feedback_elements" for "element_feedbacks_feedback_elements". FeedbackElement.ransack("step_id_eq"=>148, "s"=>"element_feedback_element_position").result.to_sql
Here is an ActiveRecord version that works: FeedbackElement.left_outer_joins(:step, element_feedback: :element).where(steps: {id: 148}).order("elements_element_feedbacks.position").to_sql
|
I have faced the same issue with Rails 6.0.2 and Ransack 2.4.0 After upgrading Rails version to 6.1.0 it all works well |
👍 |
In my case after upgrading to 6.1.0 I no longer get an error, but I still also do not get the expected result - the search just comes back empty, so there is still an issue. SELECT "sources".* FROM "sources" 6.0.0 ransack 2.4.0 works as desired/expected and the same query generates: SELECT "sources".* FROM "sources" So 6.1.0 is using one less JOIN which actually looks OK. I don't see what's wrong with the 6.1.0 query, but it definitely does not do what I expect. |
Having thought about this some more it is clear what the problem is here. I have class Source < ApplicationRecord If the 6.1.0 query only joins with the sourcetags table once it will never generate a row with two distinct tags. So the additional JOIN in the 6.0.0 case is both correct and necessary. |
I have a solution working with 6.1.0. I changed the model file to have: class Source < ApplicationRecord and now the query is: SELECT "sources".* FROM "sources" which returns the same result I had with 6.0.0. |
I still have issues running against the master version here on Github (currently Ransack 2.4.2) and Rails 6.1.1:
Notice that |
This one is still haunting me :'-( |
#1447 is likely to have fixed this, feel free to try next version! |
I use Ransack like this:
In the gem version from January the generated query looks like this (and works):
Notice the extra joins and how this line looks:
(("communes_organizations"."id" = 1045) OR ("communes_organizations_2"."id" = 1045))
Here is how it looks under the current master (and doesn't work):
Notice the missing extra joins and the same line which now uses the same relation instead of two different ones:
(("communes_organizations"."id" = 1029) OR ("communes_organizations"."id" = 1029))
The text was updated successfully, but these errors were encountered: