From 1e8d400534b2e5aff530f207f70e44cde98e170e Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Fri, 6 Nov 2020 17:42:02 +0000 Subject: [PATCH] Add Paranoia#delete (original) --- config/initializers/paranoia.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 config/initializers/paranoia.rb diff --git a/config/initializers/paranoia.rb b/config/initializers/paranoia.rb new file mode 100644 index 0000000000..f0e5cf8ea1 --- /dev/null +++ b/config/initializers/paranoia.rb @@ -0,0 +1,15 @@ +module Paranoia + def paranoia_delete + raise ActiveRecord::ReadOnlyRecord, "#{self.class} is marked as readonly" if readonly? + if persisted? + # if a transaction exists, add the record so that after_commit + # callbacks can be run + add_to_transaction + update_columns(paranoia_destroy_attributes) + elsif !frozen? + assign_attributes(paranoia_destroy_attributes) + end + self + end + alias_method :delete, :paranoia_delete +end