Order translations using ruby

Joining the translations table caused duplicate records to appear.
Ordering with SQL is simply too hard because we need to consider
fallback locales.

Thanks Senén for providing most of the tests in the poll spec.
This commit is contained in:
Javi Martín
2019-05-31 13:41:01 +02:00
parent 90c1d681d0
commit dadbf873ba
11 changed files with 131 additions and 14 deletions

View File

@@ -40,8 +40,7 @@ class Budget
delegate :budget, :budget_id, to: :group, allow_nil: true
scope :i18n, -> { joins(:translations) }
scope :allow_custom_content, -> { i18n.where(allow_custom_content: true).order("budget_heading_translations.name") }
scope :allow_custom_content, -> { where(allow_custom_content: true).sort_by(&:name) }
def self.sort_by_name
all.sort do |heading, other_heading|