-
-
Notifications
You must be signed in to change notification settings - Fork 829
Description
I use the globalize gem for managing internationalized attributes of models. When I try to sort on the translated attribute of an association and add a custom join to the translations of the main model (as is also done when using Globalize's with_translation
scope), then the sorting breaks. Ransack doesn't add the join to association's translations table and order on the association's translated attribute any longer.
So suppose you have a Book with a translated title attribute, and each Book has a Category with a translated name attribute. The following doesn't work any longer: Book.joins(:translations).ransack({ s: ['category_translations_name asc'] }).result
It yields the following query: SELECT \"books\".* FROM \"books\" INNER JOIN \"book_translations\" ON \"book_translations\".\"book_id\" = \"books\".\"id\" LEFT OUTER JOIN \"categories\" ON \"categories\".\"id\" = \"books\".\"category_id\"
See for more details and examples the following gist test: https://gist.github.com/kreintjes/a85b610afcfc87f4f680b874098a2e01
This worked in version 1.8.7 of Ransack, but stopped working when updating to Ransack 2. I believe the problem is caused by the change introduced in #937. When reverting this change two of the three failing cases pass, while the last fails with a different error.
Might not be Globalize related, but potentially also happens when sorting on an association of an association while joining an association (with the same name).
Versions
Ruby 2.4.1
Rails 5.0.4
Ransack 2.0.1
Globalize 5.1.0