diff --git a/app/models/pet.rb b/app/models/pet.rb index 6e2d6c2c..ca4637a7 100644 --- a/app/models/pet.rb +++ b/app/models/pet.rb @@ -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), diff --git a/app/models/pet_type.rb b/app/models/pet_type.rb index 720577a0..1d503c3f 100644 --- a/app/models/pet_type.rb +++ b/app/models/pet_type.rb @@ -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