I've recently been using Rick Olson's plugin, acts_as_paranoid, to mark records as deleted rather than actually destroying them. When I had my model acting very paranoid, I found myself wanting to ignore the 'deleted' records when validating newly created records. For instance, I have an Account model:
class Account < ActiveRecord::Base
acts_as_paranoid
#Validations
validates_uniqueness_of :subdomain
end
As it stands, when I create a new account object with a subdomain of "foo" and try to save it, it will be invalid even if the existing record with the "foo" subdomain has been marked as deleted. I needed to treat the deleted records as if they no longer existed. To remedy this problem, I overwrote validates_uniqueness_of inside acts_as_paranoid to take an option to exclude deleted records.
So after updating the plugin, I can pass the :without_deleted => true option to validates_uniqueness_of and the record will be valid if no other active records have the same subdomain. Here's the whopping 1/2 line change to the model:
class Account < ActiveRecord::Base
acts_as_paranoid
#Validations
validates_uniqueness_of :subdomain, :without_deleted => true
end
And that's it! Pretty simple change, but I found it useful. I don't know if this is something anyone else needs to do, but feel free to grab my version of acts_as_paranoid from my github repository if it helps.
