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:
parent
e9b0fa0779
commit
15a905b0dd
2 changed files with 8 additions and 4 deletions
|
@ -86,8 +86,8 @@ class Pet < ApplicationRecord
|
||||||
def wardrobe_query
|
def wardrobe_query
|
||||||
{
|
{
|
||||||
name: self.name,
|
name: self.name,
|
||||||
color: self.pet_type.color.id,
|
color: self.pet_type.color_id,
|
||||||
species: self.pet_type.species.id,
|
species: self.pet_type.species_id,
|
||||||
pose: self.pet_state.pose,
|
pose: self.pet_state.pose,
|
||||||
state: self.pet_state.id,
|
state: self.pet_state.id,
|
||||||
objects: self.items.map(&:id),
|
objects: self.items.map(&:id),
|
||||||
|
|
|
@ -3,8 +3,12 @@ class PetType < ApplicationRecord
|
||||||
IMAGE_CP_LOCATION_REGEX = %r{^/cp/(.+?)/[0-9]+/[0-9]+\.png$};
|
IMAGE_CP_LOCATION_REGEX = %r{^/cp/(.+?)/[0-9]+/[0-9]+\.png$};
|
||||||
IMAGE_CPN_ACCEPTABLE_NAME = /^[a-z0-9_]+$/
|
IMAGE_CPN_ACCEPTABLE_NAME = /^[a-z0-9_]+$/
|
||||||
|
|
||||||
belongs_to :species
|
# NOTE: While a pet type does always functionally belong to a color and
|
||||||
belongs_to :color
|
# 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_one :contribution, :as => :contributed, :inverse_of => :contributed
|
||||||
has_many :pet_states
|
has_many :pet_states
|
||||||
has_many :pets
|
has_many :pets
|
||||||
|
|
Loading…
Reference in a new issue