Fix bug with Arel ordering
Ok so weird little situation, usually Arel will accept an attribute as a param to `order()`, but not when it's in a very specific situation of all of the following: `Item.joins(:translations).includes(:translations).limit(30).order(Item::Translation.arel_table[:name])` For some reason, it's all like "hey I can't call `to_sql` on an attribute!", but only in the scenario where all 3 of those other things are present. Weird! Anyway, explicitly saying `.asc` fixes this. Ok!
This commit is contained in:
parent
c2866f832d
commit
111d4dcaee
5 changed files with 15 additions and 8 deletions
|
@ -12,9 +12,9 @@ class ClosetHanger < ApplicationRecord
|
|||
validate :list_belongs_to_user
|
||||
|
||||
scope :alphabetical_by_item_name, -> {
|
||||
joins(:item => :translations).
|
||||
where(Item::Translation.arel_table[:locale].eq(I18n.locale)).
|
||||
order(Item::Translation.arel_table[:name])
|
||||
it = Item::Translation.arel_table
|
||||
joins(:item => :translations).where(it[:locale].eq(I18n.locale)).
|
||||
order(it[:name].asc)
|
||||
}
|
||||
scope :newest, -> { order(arel_table[:created_at].desc) }
|
||||
scope :owned_before_wanted, -> { order(arel_table[:owned].desc) }
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
class Color < ApplicationRecord
|
||||
translates :name
|
||||
|
||||
scope :alphabetical, -> { with_translations(I18n.locale).order(Color::Translation.arel_table[:name]) }
|
||||
scope :alphabetical, -> {
|
||||
ct = Color::Translation.arel_table
|
||||
with_translations(I18n.locale).order(ct[:name].asc)
|
||||
}
|
||||
scope :basic, -> { where(:basic => true) }
|
||||
scope :standard, -> { where(:standard => true) }
|
||||
scope :nonstandard, -> { where(:standard => false) }
|
||||
|
|
|
@ -27,7 +27,7 @@ class Item < ApplicationRecord
|
|||
locale = locale or I18n.locale
|
||||
it = Item::Translation.arel_table
|
||||
joins(:translations).where(it[:locale].eq('en')).
|
||||
order(it[:name])
|
||||
order(it[:name].asc)
|
||||
}
|
||||
|
||||
scope :newest, -> {
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
class Species < ApplicationRecord
|
||||
translates :name
|
||||
|
||||
scope :alphabetical, -> { with_translations(I18n.locale).order(Species::Translation.arel_table[:name]) }
|
||||
scope :alphabetical, -> {
|
||||
st = Species::Translation.arel_table
|
||||
with_translations(I18n.locale).order(st[:name].asc)
|
||||
}
|
||||
|
||||
scope :matching_name, ->(name, locale = I18n.locale) {
|
||||
st = Species::Translation.arel_table
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class Zone < ApplicationRecord
|
||||
class Zone < ActiveRecord::Base
|
||||
translates :label, :plain_label
|
||||
|
||||
# When selecting zones that an asset occupies, we allow the zone to set
|
||||
|
@ -6,7 +6,8 @@ class Zone < ApplicationRecord
|
|||
attr_writer :sometimes
|
||||
|
||||
scope :alphabetical, -> {
|
||||
with_translations(I18n.locale).order(Zone::Translation.arel_table[:label])
|
||||
zt = Zone::Translation.arel_table
|
||||
with_translations(I18n.locale).order(zt[:label].asc)
|
||||
}
|
||||
scope :includes_translations, -> { includes(:translations) }
|
||||
scope :matching_label, ->(label, locale = I18n.locale) {
|
||||
|
|
Loading…
Reference in a new issue