Allow modeling pets for colors we haven't gotten metadata for yet

This used to be the behavior, and the site has plenty of graceful
fallbacks for it, I just forgot this one when doing Rails upgrades!

Note that the impress-2020 stuff is *not* as graceful about this, so
the wardrobe page won't show the pet until the color is in the DB. Ah
well, still an improvement!
This commit is contained in:
Emi Matchu 2024-02-16 23:22:41 -08:00
parent e9b0fa0779
commit 15a905b0dd
2 changed files with 8 additions and 4 deletions

View file

@ -86,8 +86,8 @@ class Pet < ApplicationRecord
def wardrobe_query
{
name: self.name,
color: self.pet_type.color.id,
species: self.pet_type.species.id,
color: self.pet_type.color_id,
species: self.pet_type.species_id,
pose: self.pet_state.pose,
state: self.pet_state.id,
objects: self.items.map(&:id),

View file

@ -3,8 +3,12 @@ class PetType < ApplicationRecord
IMAGE_CP_LOCATION_REGEX = %r{^/cp/(.+?)/[0-9]+/[0-9]+\.png$};
IMAGE_CPN_ACCEPTABLE_NAME = /^[a-z0-9_]+$/
belongs_to :species
belongs_to :color
# NOTE: While a pet type does always functionally belong to a color and
# species, sometimes we don't have that record yet, in which case color_id
# or species_id will refer to a nonexistant record, and the site should
# generally fall back gracefully about that.
belongs_to :species, optional: true
belongs_to :color, optional: true
has_one :contribution, :as => :contributed, :inverse_of => :contributed
has_many :pet_states
has_many :pets