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
d99f42d3
Commit
d99f42d3
authored
Jan 21, 2015
by
John Hawthorn
Committed by
John Hawthorn
Jan 22, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix problem when destroying non-paranoid has_one association
Thanks @kidlab
parent
9b8158e2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
10 deletions
+18
-10
lib/paranoia.rb
+9
-8
test/paranoia_test.rb
+9
-2
No files found.
lib/paranoia.rb
View file @
d99f42d3
...
...
@@ -170,15 +170,16 @@ class ActiveRecord::Base
reflection
.
options
[
:dependent
]
==
:destroy
end
if
dependent_reflections
.
any?
dependent_reflections
.
each
do
|
name
,
_
|
associat
ed_records
=
self
.
send
(
name
)
dependent_reflections
.
each
do
|
name
,
reflection
|
associat
ion_data
=
self
.
send
(
name
)
# 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!
# .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
...
...
test/paranoia_test.rb
View file @
d99f42d3
...
...
@@ -361,9 +361,15 @@ class ParanoiaTest < test_framework
def
test_real_destroy_dependent_destroy
parent
=
ParentModel
.
create
child
=
parent
.
very_related_models
.
create
child1
=
parent
.
very_related_models
.
create
child2
=
parent
.
non_paranoid_models
.
create
child3
=
parent
.
create_non_paranoid_model
parent
.
really_destroy!
refute
RelatedModel
.
unscoped
.
exists?
(
child
.
id
)
refute
RelatedModel
.
unscoped
.
exists?
(
child1
.
id
)
refute
NonParanoidModel
.
unscoped
.
exists?
(
child2
.
id
)
refute
NonParanoidModel
.
unscoped
.
exists?
(
child3
.
id
)
end
def
test_real_destroy_dependent_destroy_after_normal_destroy
...
...
@@ -757,6 +763,7 @@ class ParentModel < ActiveRecord::Base
has_many
:related_models
has_many
:very_related_models
,
:class_name
=>
'RelatedModel'
,
dependent: :destroy
has_many
:non_paranoid_models
,
dependent: :destroy
has_one
:non_paranoid_model
,
dependent: :destroy
has_many
:asplode_models
,
dependent: :destroy
has_one
:polymorphic_model
,
as: :parent
,
dependent: :destroy
end
...
...
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