Commit a3179441 by Sammy Larbi

Ensure uniqueness validation is scoped by deleted_at

Fixes #114
parent 6b6efeec
...@@ -237,3 +237,16 @@ class ActiveRecord::Base ...@@ -237,3 +237,16 @@ class ActiveRecord::Base
end end
require 'paranoia/rspec' if defined? RSpec require 'paranoia/rspec' if defined? RSpec
module ActiveRecord
module Validations
class UniquenessValidator < ActiveModel::EachValidator
protected
def build_relation_with_paranoia(klass, table, attribute, value)
relation = build_relation_without_paranoia(klass, table, attribute, value)
relation.and(klass.arel_table[klass.paranoia_column].eq(nil))
end
alias_method_chain :build_relation, :paranoia
end
end
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