Commit c2a1dfac by Claessens Simon Committed by John Hawthorn

Use module.prepend instead of alias_method_chain

parent fc4cec00
...@@ -261,14 +261,16 @@ require 'paranoia/rspec' if defined? RSpec ...@@ -261,14 +261,16 @@ require 'paranoia/rspec' if defined? RSpec
module ActiveRecord module ActiveRecord
module Validations module Validations
class UniquenessValidator < ActiveModel::EachValidator module UniquenessParanoiaValidator
protected def build_relation(klass, table, attribute, value)
def build_relation_with_paranoia(klass, table, attribute, value) relation = super(klass, table, attribute, value)
relation = build_relation_without_paranoia(klass, table, attribute, value)
return relation unless klass.respond_to?(:paranoia_column) return relation unless klass.respond_to?(:paranoia_column)
relation.and(klass.arel_table[klass.paranoia_column].eq(klass.paranoia_sentinel_value)) relation.and(klass.arel_table[klass.paranoia_column].eq(klass.paranoia_sentinel_value))
end end
alias_method_chain :build_relation, :paranoia end
class UniquenessValidator < ActiveModel::EachValidator
prepend UniquenessParanoiaValidator
end end
end 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