Commit 5058797e by Nikolay Norkin

real_destroy callback

parent df42daa3
...@@ -47,7 +47,7 @@ module Paranoia ...@@ -47,7 +47,7 @@ module Paranoia
module Callbacks module Callbacks
def self.extended(klazz) def self.extended(klazz)
klazz.define_callbacks :restore klazz.define_callbacks :restore, :real_destroy
klazz.define_singleton_method("before_restore") do |*args, &block| klazz.define_singleton_method("before_restore") do |*args, &block|
set_callback(:restore, :before, *args, &block) set_callback(:restore, :before, *args, &block)
...@@ -172,6 +172,8 @@ class ActiveRecord::Base ...@@ -172,6 +172,8 @@ class ActiveRecord::Base
alias :destroy_without_paranoia :destroy alias :destroy_without_paranoia :destroy
def really_destroy! def really_destroy!
transaction do
run_callbacks(:real_destroy) do
dependent_reflections = self.class.reflections.select do |name, reflection| dependent_reflections = self.class.reflections.select do |name, reflection|
reflection.options[:dependent] == :destroy reflection.options[:dependent] == :destroy
end end
...@@ -192,6 +194,8 @@ class ActiveRecord::Base ...@@ -192,6 +194,8 @@ class ActiveRecord::Base
write_attribute(paranoia_column, current_time_from_proper_timezone) write_attribute(paranoia_column, current_time_from_proper_timezone)
destroy_without_paranoia destroy_without_paranoia
end end
end
end
include Paranoia include Paranoia
class_attribute :paranoia_column, :paranoia_sentinel_value class_attribute :paranoia_column, :paranoia_sentinel_value
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment