Because we ended up with such a big error, and it doesn't have an easy fix, I'm wrapping up today by reverting the entire set of refactors we've done lately, so modeling in production can continue while we improve this code further over time. I generated this commit by hand-picking the refactor-y commits recently, running `git revert --no-commit <hash>` in reverse order, then manually updating `pet_spec.rb` to reflect the state of the code: passing the most important behavioral tests, but no longer passing one of the kinds of annoyances I *did* fix in the new code. ```shell git revert --no-commit48c1a58df9git revert --no-commit42e7eabdd8git revert --no-commitd82c7f817agit revert --no-commit5264947608git revert --no-commit90407403bagit revert --no-commit242b85470dgit revert --no-commit9eaee4a2d4git revert --no-commit52ca41dbffgit revert --no-commitc03e7446e3git revert --no-commitf81415d327git revert --no-commit13ceec8fcc```
26 lines
525 B
Ruby
26 lines
525 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
|