diff options
Diffstat (limited to 'app/models/page.rb')
| -rw-r--r-- | app/models/page.rb | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/app/models/page.rb b/app/models/page.rb index 385b3f6..c982c2e 100644 --- a/app/models/page.rb +++ b/app/models/page.rb | |||
| @@ -63,15 +63,15 @@ class Page < ApplicationRecord | |||
| 63 | end | 63 | end |
| 64 | end | 64 | end |
| 65 | 65 | ||
| 66 | direction = %w[ASC DESC].include?(options[:order_direction]&.upcase) ? options[:order_direction].upcase : "ASC" | ||
| 67 | |||
| 66 | if options[:order_by] == "title" | 68 | if options[:order_by] == "title" |
| 67 | return scope | 69 | return scope |
| 68 | .joins(:translations) | 70 | .order(Arel.sql("(SELECT pt.title FROM page_translations pt WHERE pt.page_id = pages.id AND pt.locale = #{ActiveRecord::Base.connection.quote(I18n.locale.to_s)}) #{direction}")) |
| 69 | .where(page_translations: { locale: I18n.locale }) | ||
| 70 | .order("page_translations.title #{options[:order_direction]}") | ||
| 71 | .paginate(:page => page, :per_page => options[:limit]) | 71 | .paginate(:page => page, :per_page => options[:limit]) |
| 72 | end | 72 | end |
| 73 | 73 | ||
| 74 | scope.order("#{options[:order_by]} #{options[:order_direction]}") | 74 | scope.order("#{options[:order_by]} #{direction}") |
| 75 | .paginate(:page => page, :per_page => options[:limit]) | 75 | .paginate(:page => page, :per_page => options[:limit]) |
| 76 | end | 76 | end |
| 77 | 77 | ||
