Commit c3e840e8 by Aditya Sanghi

Adding only_deleted scope and updating readme with some compatibility comments.

parent e0e1d300
......@@ -62,15 +62,13 @@ If you want a method to be called on destroy, simply provide a _before\_destroy_
You can replace the older acts_as_paranoid methods as follows:
find_with_deleted(:all) => unscoped
find_with_deleted(:first) => unscoped.first
find_with_deleted(id) => unscoped.find(id)
find_with_deleted([id1,id2]) => unscoped.find([id1,id2])
find_only_deleted(:all) => unscoped.where("deleted_at is not null")
find_only_deleted(:first) => unscoped.where("deleted_at is not null").first
find_only_deleted(id) => unscoped.where("deleted_at is not null").find(id)
find_only_deleted([id1,id2]) => unscoped.where("deleted_at is not null").find([id1,id2])
find_with_deleted(:all) # => unscoped
find_with_deleted(:first) # => unscoped.first
find_with_deleted(id) # => unscoped.find(id)
find_only_deleted(:all) # => only_deleted
find_only_deleted(:first) # => only_deleted.first
find_only_deleted(id) # => only_deleted.find(id)
## License
......
......@@ -5,6 +5,12 @@ module Paranoia
module Query
def paranoid? ; true ; end
def only_deleted
unscoped {
where("deleted_at is not null")
}
end
end
def destroy
......
......@@ -38,7 +38,7 @@ class ParanoiaTest < Test::Unit::TestCase
assert_equal true, model.deleted_at.nil?
assert model.frozen?
assert_equal 0, model.class.count
assert_equal 0, model.class.unscoped.count
end
......@@ -66,11 +66,22 @@ class ParanoiaTest < Test::Unit::TestCase
model.delete
assert_equal false, model.deleted_at.nil?
assert_equal 0, model.class.count
assert_equal 1, model.class.unscoped.count
end
def test_only_deleted_scope_for_paranoid_models
model = ParanoidModel.new
model.save
model.delete
model2 = ParanoidModel.new
model2.save
assert_equal model, ParanoidModel.only_deleted.last
assert_equal false, ParanoidModel.only_deleted.include?(model2)
end
private
def get_featureful_model
FeaturefulModel.new(:name => "not empty")
......
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