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
65649aa4
Commit
65649aa4
authored
Mar 21, 2018
by
Bartosz Bonisławski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Monkeypatch activerecord relations to work with rails >=5.2.0rc2
parent
a3286408
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
2 deletions
+44
-2
.travis.yml
+2
-2
lib/paranoia.rb
+1
-0
lib/paranoia/active_record_patches.rb
+41
-0
No files found.
.travis.yml
View file @
65649aa4
...
@@ -14,7 +14,7 @@ env:
...
@@ -14,7 +14,7 @@ env:
-
RAILS='~> 4.2.0'
-
RAILS='~> 4.2.0'
-
RAILS='~> 5.0.0'
-
RAILS='~> 5.0.0'
-
RAILS='~> 5.1.0'
-
RAILS='~> 5.1.0'
-
RAILS='~> 5.2.0.
beta
2'
-
RAILS='~> 5.2.0.
rc
2'
matrix
:
matrix
:
allow_failures
:
allow_failures
:
...
@@ -24,5 +24,5 @@ matrix:
...
@@ -24,5 +24,5 @@ matrix:
rvm
:
jruby-9.1.6.0
rvm
:
jruby-9.1.6.0
-
env
:
RAILS='~> 5.1.0'
-
env
:
RAILS='~> 5.1.0'
rvm
:
jruby-9.1.6.0
rvm
:
jruby-9.1.6.0
-
env
:
RAILS='~> 5.2.0.
beta
2'
-
env
:
RAILS='~> 5.2.0.
rc
2'
rvm
:
jruby-9.1.6.0
rvm
:
jruby-9.1.6.0
lib/paranoia.rb
View file @
65649aa4
require
'active_record'
unless
defined?
ActiveRecord
require
'active_record'
unless
defined?
ActiveRecord
require
'paranoia/active_record_patches'
module
Paranoia
module
Paranoia
@@default_sentinel_value
=
nil
@@default_sentinel_value
=
nil
...
...
lib/paranoia/active_record_patches.rb
0 → 100644
View file @
65649aa4
module
HandleParanoiaDestroyedInBelongsToAssociation
def
handle_dependency
return
unless
load_target
case
options
[
:dependent
]
when
:destroy
target
.
destroy
if
defined?
target
.
deleted?
raise
ActiveRecord
::
Rollback
unless
target
.
deleted?
else
raise
ActiveRecord
::
Rollback
unless
target
.
destroyed?
end
else
target
.
send
(
options
[
:dependent
])
end
end
end
module
HandleParanoiaDestroyedInHasOneAssociation
def
delete
(
method
=
options
[
:dependent
])
if
load_target
case
method
when
:delete
target
.
delete
when
:destroy
target
.
destroyed_by_association
=
reflection
target
.
destroy
if
defined?
target
.
deleted?
throw
(
:abort
)
unless
target
.
deleted?
else
throw
(
:abort
)
unless
target
.
destroyed?
end
when
:nullify
target
.
update_columns
(
reflection
.
foreign_key
=>
nil
)
if
target
.
persisted?
end
end
end
end
ActiveRecord
::
Associations
::
BelongsToAssociation
.
prepend
HandleParanoiaDestroyedInBelongsToAssociation
ActiveRecord
::
Associations
::
HasOneAssociation
.
prepend
HandleParanoiaDestroyedInHasOneAssociation
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