Commit 5058797e by Nikolay Norkin

real_destroy callback

parent df42daa3
......@@ -47,7 +47,7 @@ module Paranoia
module Callbacks
def self.extended(klazz)
klazz.define_callbacks :restore
klazz.define_callbacks :restore, :real_destroy
klazz.define_singleton_method("before_restore") do |*args, &block|
set_callback(:restore, :before, *args, &block)
......@@ -172,25 +172,29 @@ class ActiveRecord::Base
alias :destroy_without_paranoia :destroy
def really_destroy!
dependent_reflections = self.class.reflections.select do |name, reflection|
reflection.options[:dependent] == :destroy
end
if dependent_reflections.any?
dependent_reflections.each do |name, reflection|
association_data = self.send(name)
# has_one association can return nil
# .paranoid? will work for both instances and classes
if association_data && association_data.paranoid?
if reflection.collection?
association_data.with_deleted.each(&:really_destroy!)
else
association_data.really_destroy!
transaction do
run_callbacks(:real_destroy) do
dependent_reflections = self.class.reflections.select do |name, reflection|
reflection.options[:dependent] == :destroy
end
if dependent_reflections.any?
dependent_reflections.each do |name, reflection|
association_data = self.send(name)
# has_one association can return nil
# .paranoid? will work for both instances and classes
if association_data && association_data.paranoid?
if reflection.collection?
association_data.with_deleted.each(&:really_destroy!)
else
association_data.really_destroy!
end
end
end
end
write_attribute(paranoia_column, current_time_from_proper_timezone)
destroy_without_paranoia
end
end
write_attribute(paranoia_column, current_time_from_proper_timezone)
destroy_without_paranoia
end
include Paranoia
......
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