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
68446622
Commit
68446622
authored
Feb 01, 2016
by
John Hawthorn
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #301 from westonganger/rails4
Added without_default_scope option
parents
31e8850c
6d90b426
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
2 deletions
+29
-2
README.md
+11
-0
lib/paranoia.rb
+4
-1
test/paranoia_test.rb
+14
-1
No files found.
README.md
View file @
68446622
...
@@ -104,6 +104,17 @@ class Client < ActiveRecord::Base
...
@@ -104,6 +104,17 @@ class Client < ActiveRecord::Base
end
end
```
```
If you want to skip adding the default scope
```
ruby
class
Client
<
ActiveRecord
::
Base
acts_as_paranoid
without_default_scope:
true
...
end
```
If you want to access soft-deleted associations, override the getter method:
If you want to access soft-deleted associations, override the getter method:
```
ruby
```
ruby
...
...
lib/paranoia.rb
View file @
68446622
...
@@ -219,7 +219,10 @@ class ActiveRecord::Base
...
@@ -219,7 +219,10 @@ class ActiveRecord::Base
def
self
.
paranoia_scope
def
self
.
paranoia_scope
where
(
paranoia_column
=>
paranoia_sentinel_value
)
where
(
paranoia_column
=>
paranoia_sentinel_value
)
end
end
default_scope
{
paranoia_scope
}
unless
options
[
:without_default_scope
]
default_scope
{
paranoia_scope
}
end
before_restore
{
before_restore
{
self
.
class
.
notify_observers
(
:before_restore
,
self
)
if
self
.
class
.
respond_to?
(
:notify_observers
)
self
.
class
.
notify_observers
(
:before_restore
,
self
)
if
self
.
class
.
respond_to?
(
:notify_observers
)
...
...
test/paranoia_test.rb
View file @
68446622
...
@@ -40,7 +40,8 @@ def setup!
...
@@ -40,7 +40,8 @@ def setup!
'namespaced_paranoid_belongs_tos'
=>
'deleted_at DATETIME, paranoid_has_one_id INTEGER'
,
'namespaced_paranoid_belongs_tos'
=>
'deleted_at DATETIME, paranoid_has_one_id INTEGER'
,
'unparanoid_unique_models'
=>
'name VARCHAR(32), paranoid_with_unparanoids_id INTEGER'
,
'unparanoid_unique_models'
=>
'name VARCHAR(32), paranoid_with_unparanoids_id INTEGER'
,
'active_column_models'
=>
'deleted_at DATETIME, active BOOLEAN'
,
'active_column_models'
=>
'deleted_at DATETIME, active BOOLEAN'
,
'active_column_model_with_uniqueness_validations'
=>
'name VARCHAR(32), deleted_at DATETIME, active BOOLEAN'
'active_column_model_with_uniqueness_validations'
=>
'name VARCHAR(32), deleted_at DATETIME, active BOOLEAN'
,
'without_default_scope_models'
=>
'deleted_at DATETIME'
}.
each
do
|
table_name
,
columns_as_sql_string
|
}.
each
do
|
table_name
,
columns_as_sql_string
|
ActiveRecord
::
Base
.
connection
.
execute
"CREATE TABLE
#{
table_name
}
(id INTEGER NOT NULL PRIMARY KEY,
#{
columns_as_sql_string
}
)"
ActiveRecord
::
Base
.
connection
.
execute
"CREATE TABLE
#{
table_name
}
(id INTEGER NOT NULL PRIMARY KEY,
#{
columns_as_sql_string
}
)"
end
end
...
@@ -204,6 +205,14 @@ class ParanoiaTest < test_framework
...
@@ -204,6 +205,14 @@ class ParanoiaTest < test_framework
assert_equal
nil
,
ParanoidModel
.
paranoia_sentinel_value
assert_equal
nil
,
ParanoidModel
.
paranoia_sentinel_value
end
end
def
test_without_default_scope_option
model
=
WithoutDefaultScopeModel
.
create
model
.
destroy
assert_equal
1
,
model
.
class
.
count
assert_equal
1
,
model
.
class
.
only_deleted
.
count
assert_equal
0
,
model
.
class
.
where
(
deleted_at:
nil
).
count
end
def
test_active_column_model
def
test_active_column_model
model
=
ActiveColumnModel
.
new
model
=
ActiveColumnModel
.
new
assert_equal
0
,
model
.
class
.
count
assert_equal
0
,
model
.
class
.
count
...
@@ -1042,6 +1051,10 @@ class CustomSentinelModel < ActiveRecord::Base
...
@@ -1042,6 +1051,10 @@ class CustomSentinelModel < ActiveRecord::Base
acts_as_paranoid
sentinel_value:
DateTime
.
new
(
0
)
acts_as_paranoid
sentinel_value:
DateTime
.
new
(
0
)
end
end
class
WithoutDefaultScopeModel
<
ActiveRecord
::
Base
acts_as_paranoid
without_default_scope:
true
end
class
ActiveColumnModel
<
ActiveRecord
::
Base
class
ActiveColumnModel
<
ActiveRecord
::
Base
acts_as_paranoid
column: :active
,
sentinel_value:
true
acts_as_paranoid
column: :active
,
sentinel_value:
true
...
...
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