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
9e0ec38e
Commit
9e0ec38e
authored
Feb 07, 2016
by
Kurtis Rainbolt-Greene
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #305 from rbr/scope-without-deleted
Add scope without_deleted
parents
aa04d5d9
aa73c8f3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
2 deletions
+11
-2
README.md
+7
-1
lib/paranoia.rb
+2
-1
test/paranoia_test.rb
+2
-0
No files found.
README.md
View file @
9e0ec38e
...
...
@@ -105,7 +105,7 @@ end
```
If you want to skip adding the default scope
If you want to skip adding the default scope
:
```
ruby
class
Client
<
ActiveRecord
::
Base
...
...
@@ -139,6 +139,12 @@ If you want to find all records, even those which are deleted:
Client
.
with_deleted
```
If you want to exclude deleted records, when not able to use the default_scope (e.g. when using without_default_scope):
```
ruby
Client
.
without_deleted
```
If you want to find only the deleted records:
```
ruby
...
...
lib/paranoia.rb
View file @
9e0ec38e
...
...
@@ -219,7 +219,8 @@ class ActiveRecord::Base
def
self
.
paranoia_scope
where
(
paranoia_column
=>
paranoia_sentinel_value
)
end
class
<<
self
;
alias_method
:without_deleted
,
:paranoia_scope
end
unless
options
[
:without_default_scope
]
default_scope
{
paranoia_scope
}
end
...
...
test/paranoia_test.rb
View file @
9e0ec38e
...
...
@@ -186,8 +186,10 @@ class ParanoiaTest < test_framework
assert_equal
0
,
parent1
.
paranoid_models
.
count
assert_equal
1
,
parent1
.
paranoid_models
.
only_deleted
.
count
assert_equal
1
,
parent1
.
paranoid_models
.
deleted
.
count
assert_equal
0
,
parent1
.
paranoid_models
.
without_deleted
.
count
p3
=
ParanoidModel
.
create
(
:parent_model
=>
parent1
)
assert_equal
2
,
parent1
.
paranoid_models
.
with_deleted
.
count
assert_equal
1
,
parent1
.
paranoid_models
.
without_deleted
.
count
assert_equal
[
p1
,
p3
],
parent1
.
paranoid_models
.
with_deleted
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