Last active
December 10, 2015 20:48
-
-
Save EdwardTippett/4490840 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def set_deleted_at(value) | |
return self unless is_permanent? | |
record = self.class | |
record = record.unscoped if active_record_3? | |
record = record.find(id) | |
record.deleted_at = value | |
begin | |
# we call save! instead of update_attribute so an ActiveRecord::RecordInvalid | |
# error will be raised if the record isn't valid. (This prevents reviving records that | |
# disregard validation constraints,) | |
# run validations when trying to revive a record | |
value == nil ? record.save! : record.save!(:validate => false) | |
@attributes, @attributes_cache = record.attributes, record.attributes | |
rescue Exception => e | |
# trigger dependent record destruction (they were revived before this record, | |
# which cannot be revived due to validations) | |
record.destroy | |
raise e | |
end | |
end |
lengarvey
commented
Jan 9, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment