Commit aa73c8f3 by rbr Committed by René Braun

Add scope without_deleted

Add a without_deleted scope to manually exclude paranoia-deleted records, which is essentially the paranoia_scope.
Useful when using the option :without_default_scope or the unscoping of a paranoia-model was required.
Aliased it to the paranoia_scope as opposed to the existing with_deleted scope.
parent 8f6a10ec
......@@ -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
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment