acts_as_revisable
acts_as_revisable copied to clipboard
(STI) Revisions of destroyed records does not update 'type' and 'revision_type' attributes
This is using Single Table Inheritance. The issue is easily remediated with my childish method:
acts_as_revisable do
revision_class_name "AccountRevision"
except [:update_tracker, :last_login_on, :last_update_on, :last_login_at,
:password_changed_on, :updated_at, :revoked_on, :resumed_on]
end
acts_as_revisable :on_delete => :revise
after_revise_on_destroy :arod!
def arod!
print "poop poop!!\n"
self.revisable_type = self.type
self.type = "#{self.type}Revision"
self.revisable_original_id = self.id
if self.save
return true
else
return false
end
end
hahaha, it says "poop poop." What a cute definition (snuggles).
I'm porting my models into a new Rails project for cleanliness sake and just realized this issue again. Example:
>> RacfAccount.count => 9319 >> RacfAccountRevision.count => 16 >> Account.count => 9319 >> AccountRevision.count => 26 >>
The AccountRevision is showing records for which the '.destroy' method has been used. The 'type' attribute continues to reflect "RacfAccount" and not "RacfAccountRevision", and the 'revision_type' is set to NULL. However, when doing a simple revision (but not destroy) of a RacfAccount record, it will correctly set the 'type' and 'revision_type' attributes (by default).
Thank you!