I want to order some records of a model that has a relation to another model (with translated attributes). Here an example:
- I have a model Project
- I have a model Task
- I have the relation Project has_many Tasks
- The model Task has attribute name globalized (on task_translations table)
Now, I want to order all projects by its tasks name. How can I write this scope? How can I join the translation table in Rails like method with_translation in gem globalize (https://github.com/globalize/globalize/blob/eccb924ac9641b52399f22525b0e3ec004739f4c/lib/globalize/active_record/class_methods.rb) but from related object Project?
> Project.all.joins(:tasks) ... (how to include task translation table) ...
Project.joins(tasks: :translations).where("task_translations.name = ?", "todo") }
– Montelongo