Emi Matchu
42e7eabdd8
Ah right, the callbacks in `ParentSwfAssetRelationship` don't get called when Rails does automatic join-model management stuff. We need the `Item` to call its `update_cached_fields` callback itself, too! When fixing this, I found a new bug that arose, in how we infer `body_id` for assets that fit all pets. Fixing that next!
26 lines
523 B
Ruby
26 lines
523 B
Ruby
class ParentSwfAssetRelationship < ApplicationRecord
|
|
self.table_name = 'parents_swf_assets'
|
|
|
|
belongs_to :parent, polymorphic: true
|
|
|
|
belongs_to :swf_asset
|
|
|
|
after_save :update_parent_cached_fields
|
|
after_destroy :update_parent_cached_fields
|
|
|
|
def item=(replacement)
|
|
self.parent = replacement
|
|
end
|
|
|
|
def pet_state
|
|
PetState.find(parent_id)
|
|
end
|
|
|
|
def pet_state=(replacement)
|
|
self.parent = replacement
|
|
end
|
|
|
|
def update_parent_cached_fields
|
|
parent.try(:update_cached_fields!)
|
|
end
|
|
end
|