Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paranoia
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paranoia
Commits
5058797e
Commit
5058797e
authored
Apr 07, 2015
by
Nikolay Norkin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
real_destroy callback
parent
df42daa3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
16 deletions
+20
-16
lib/paranoia.rb
+20
-16
No files found.
lib/paranoia.rb
View file @
5058797e
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment