Commit 9e0ec38e by Kurtis Rainbolt-Greene

Merge pull request #305 from rbr/scope-without-deleted

Add scope without_deleted
parents aa04d5d9 aa73c8f3
......@@ -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