Use arel for item translation joins
Just a bit defensive so we aren't setting up the possibility of an ambiguous query someday!
This commit is contained in:
parent
a653b0c20d
commit
185b4eb2fc
1 changed files with 12 additions and 10 deletions
|
@ -48,30 +48,32 @@ class Item < ActiveRecord::Base
|
||||||
scope :with_closet_hangers, -> { joins(:closet_hangers) }
|
scope :with_closet_hangers, -> { joins(:closet_hangers) }
|
||||||
|
|
||||||
scope :name_includes, ->(value, locale = I18n.locale) {
|
scope :name_includes, ->(value, locale = I18n.locale) {
|
||||||
Item.joins(:translations).where('locale = ?', locale).
|
it = Item::Translation.arel_table
|
||||||
where('name LIKE ?', '%' + Item.sanitize_sql_like(value) + '%')
|
Item.joins(:translations).where(it[:locale].eq(locale)).
|
||||||
|
where(it[:name].matches('%' + Item.sanitize_sql_like(value) + '%'))
|
||||||
}
|
}
|
||||||
scope :name_excludes, ->(value, locale = I18n.locale) {
|
scope :name_excludes, ->(value, locale = I18n.locale) {
|
||||||
Item.joins(:translations).where('locale = ?', locale).
|
it = Item::Translation.arel_table
|
||||||
where('name NOT LIKE ?', '%' + Item.sanitize_sql_like(value) + '%')
|
Item.joins(:translations).where(it[:locale].eq(locale)).
|
||||||
|
where(it[:name].matches('%' + Item.sanitize_sql_like(value) + '%').not)
|
||||||
}
|
}
|
||||||
scope :is_nc, -> {
|
scope :is_nc, -> {
|
||||||
i = Item.arel_table
|
i = Item.arel_table
|
||||||
condition = i[:rarity_index].in(Item::NCRarities).or(i[:is_manually_nc])
|
where(i[:rarity_index].in(Item::NCRarities).or(i[:is_manually_nc]))
|
||||||
where(condition)
|
|
||||||
}
|
}
|
||||||
scope :is_np, -> {
|
scope :is_np, -> {
|
||||||
i = Item.arel_table
|
i = Item.arel_table
|
||||||
condition = i[:rarity_index].in(Item::NCRarities).or(i[:is_manually_nc])
|
where(i[:rarity_index].in(Item::NCRarities).or(i[:is_manually_nc]).not)
|
||||||
where(condition.not)
|
|
||||||
}
|
}
|
||||||
scope :is_pb, -> {
|
scope :is_pb, -> {
|
||||||
Item.joins(:translations).where('locale = ?', 'en').
|
it = Item::Translation.arel_table
|
||||||
|
Item.joins(:translations).where(it[:locale].eq('en')).
|
||||||
where('description LIKE ?',
|
where('description LIKE ?',
|
||||||
'%' + Item.sanitize_sql_like(PAINTBRUSH_SET_DESCRIPTION) + '%')
|
'%' + Item.sanitize_sql_like(PAINTBRUSH_SET_DESCRIPTION) + '%')
|
||||||
}
|
}
|
||||||
scope :is_not_pb, -> {
|
scope :is_not_pb, -> {
|
||||||
Item.joins(:translations).where('locale = ?', 'en').
|
it = Item::Translation.arel_table
|
||||||
|
Item.joins(:translations).where(it[:locale].eq('en')).
|
||||||
where('description NOT LIKE ?',
|
where('description NOT LIKE ?',
|
||||||
'%' + Item.sanitize_sql_like(PAINTBRUSH_SET_DESCRIPTION) + '%')
|
'%' + Item.sanitize_sql_like(PAINTBRUSH_SET_DESCRIPTION) + '%')
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue