Fix crash when searching for "is:nc"

Huh, Arel can *sometimes* handle just having an attribute stand in as
"X is true" in a condition, but sometimes gets upset about it. I guess
this changed in Rails since we recently wrote this?

Specifically, item search would crash on "is:nc" (but *not* "is:np"),
saying:

```
undefined method `fetch_attribute' for #<struct Arel::Attributes::Attribute relation=#<Arel::Table:0x0000000109a67110 @name="items", @klass=Item(…), @type_caster=#<ActiveRecord::TypeCaster::Map:0x0000000109a66e90 @klass=Item(…)>, @table_alias=nil>, name="is_manually_nc">
```

The traceback was a bit misleading (it happened at the part where we
merge all the scopes together), but that hinted to me that it working
with an attribute in a place where it expected a conditional. So I
converted the attribute in the `is_nc` scope to a conditional, and made
the matching change in `is_np`, and that fixed it! Ok phew!
This commit is contained in:
Emi Matchu 2023-10-25 12:46:48 -07:00
parent 8034e8689a
commit f8cf3fd701

View file

@ -57,11 +57,11 @@ class Item < ApplicationRecord
}
scope :is_nc, -> {
i = Item.arel_table
where(i[:rarity_index].in(Item::NCRarities).or(i[:is_manually_nc]))
where(i[:rarity_index].in(Item::NCRarities).or(i[:is_manually_nc].eq(true)))
}
scope :is_np, -> {
i = Item.arel_table
where(i[:rarity_index].in(Item::NCRarities).or(i[:is_manually_nc]).not)
where(i[:rarity_index].in(Item::NCRarities).or(i[:is_manually_nc].eq(true)).not)
}
scope :is_pb, -> {
it = Item::Translation.arel_table