Skip to content

Commit

Permalink
Ensure uniqueness validation is scoped by deleted_at
Browse files Browse the repository at this point in the history
Fixes #114
  • Loading branch information
codeodor committed Mar 16, 2014
1 parent 54fa370 commit 9999e45
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/paranoia.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,16 @@ def paranoia_column
self.class.paranoia_column
end
end

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.quoted_table_name + ".#{klass.paranoia_column} IS NULL")
end
alias_method_chain :build_relation, :paranoia
end
end
end

0 comments on commit 9999e45

Please sign in to comment.