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
acd39d7b
Commit
acd39d7b
authored
Jul 29, 2014
by
astronz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
really_destroy! and has_one associations
parent
d0e603e9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
4 deletions
+23
-4
lib/paranoia.rb
+8
-4
test/paranoia_test.rb
+15
-0
No files found.
lib/paranoia.rb
View file @
acd39d7b
...
...
@@ -154,10 +154,14 @@ class ActiveRecord::Base
if
dependent_reflections
.
any?
dependent_reflections
.
each
do
|
name
,
_
|
associated_records
=
self
.
send
(
name
)
# Paranoid models will have this method, non-paranoid models will not
associated_records
=
associated_records
.
with_deleted
if
associated_records
.
respond_to?
(
:with_deleted
)
associated_records
.
each
(
&
:really_destroy!
)
self
.
send
(
name
).
reload
# has_one association can return nil
if
associated_records
&&
associated_records
.
respond_to?
(
:with_deleted
)
# Paranoid models will have this method, non-paranoid models will not
associated_records
.
with_deleted
.
each
(
&
:really_destroy!
)
self
.
send
(
name
).
reload
elsif
associated_records
&&
!
associated_records
.
respond_to?
(
:each
)
# single record
associated_records
.
really_destroy!
end
end
end
touch_paranoia_column
if
ActiveRecord
::
VERSION
::
STRING
>=
"4.1"
...
...
test/paranoia_test.rb
View file @
acd39d7b
...
...
@@ -435,6 +435,21 @@ class ParanoiaTest < test_framework
assert
hasOne
.
reload
.
deleted_at
.
nil?
end
# covers #131
def
test_has_one_really_destroy_with_nil
model
=
ParanoidModelWithHasOne
.
create
model
.
really_destroy!
refute
ParanoidModelWithBelong
.
unscoped
.
exists?
(
model
.
id
)
end
def
test_has_one_really_destroy_with_record
model
=
ParanoidModelWithHasOne
.
create
{
|
record
|
record
.
build_paranoid_model_with_belong
}
model
.
really_destroy!
refute
ParanoidModelWithBelong
.
unscoped
.
exists?
(
model
.
id
)
end
def
test_observers_notified
a
=
ParanoidModelWithObservers
.
create
...
...
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