2023-08-02 16:05:02 -07:00
|
|
|
class ParentSwfAssetRelationship < ApplicationRecord
|
2023-07-22 12:36:04 -07:00
|
|
|
self.table_name = 'parents_swf_assets'
|
2010-05-16 12:01:38 -07:00
|
|
|
|
2024-11-06 13:39:32 -08:00
|
|
|
belongs_to :parent, polymorphic: true
|
2011-01-27 13:35:46 -08:00
|
|
|
|
2012-01-12 15:17:59 -08:00
|
|
|
belongs_to :swf_asset
|
2024-09-30 23:10:37 -07:00
|
|
|
|
|
|
|
after_save :update_parent_cached_fields
|
|
|
|
after_destroy :update_parent_cached_fields
|
2010-05-16 12:01:38 -07:00
|
|
|
|
|
|
|
def item=(replacement)
|
2012-01-12 15:17:59 -08:00
|
|
|
self.parent = replacement
|
2010-05-16 17:45:30 -07:00
|
|
|
end
|
|
|
|
|
2010-05-20 18:11:08 -07:00
|
|
|
def pet_state
|
2011-01-27 13:35:46 -08:00
|
|
|
PetState.find(parent_id)
|
2010-05-16 17:45:30 -07:00
|
|
|
end
|
|
|
|
|
2010-05-20 18:11:08 -07:00
|
|
|
def pet_state=(replacement)
|
2012-01-12 15:17:59 -08:00
|
|
|
self.parent = replacement
|
2010-05-16 12:01:38 -07:00
|
|
|
end
|
2024-09-30 23:10:37 -07:00
|
|
|
|
|
|
|
def update_parent_cached_fields
|
2024-11-06 13:39:32 -08:00
|
|
|
parent.try(:update_cached_fields!)
|
2024-09-30 23:10:37 -07:00
|
|
|
end
|
2010-05-16 12:01:38 -07:00
|
|
|
end
|