ParanoiaUniquenessValidator
Adds validates_uniqueness_without_deleted
.
This validator will ignore any record that has a non-null value for the
deleted_at
field. This gem was made specifically for use with the
Paranoia gem but it can be used with any
gem that uses the deleted_at
field for marking records as deleted.
Installation
Add this line to your application's Gemfile:
# Rails 7.0
gem 'paranoia_uniqueness_validator', '3.4.0'
# Rails 7.1
gem 'paranoia_uniqueness_validator', '3.5.0'
# Rails 7.2
gem 'paranoia_uniqueness_validator', '3.6.0'
# Rails 8.0
gem 'paranoia_uniqueness_validator', '3.7.0'
And then execute:
$ bundle
Or install it yourself as:
$ gem install paranoia_uniqueness_validator
Configuration
This validator supports all configuration options used by the base ActiveRecord uniqueness validator. For more information check out the Rails API documentation.
Usage
class SomeModel < ActiveRecord::Base
validates :some_field, uniqueness_without_deleted: true
end
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request