lib/blind_index/extensions.rb in blind_index-2.0.2 vs lib/blind_index/extensions.rb in blind_index-2.1.0
- old
+ new
@@ -27,21 +27,28 @@
@has_blind_indexes
end
end
module UniquenessValidator
+ def validate_each(record, attribute, value)
+ klass = record.class
+ if klass.respond_to?(:blind_indexes) && (bi = klass.blind_indexes[attribute])
+ value = record.read_attribute_for_validation(bi[:bidx_attribute])
+ end
+ super(record, attribute, value)
+ end
+
+ # change attribute name here instead of validate_each for better error message
if ActiveRecord::VERSION::STRING >= "5.2"
def build_relation(klass, attribute, value)
if klass.respond_to?(:blind_indexes) && (bi = klass.blind_indexes[attribute])
- value = BlindIndex.generate_bidx(value, **bi)
attribute = bi[:bidx_attribute]
end
super(klass, attribute, value)
end
else
def build_relation(klass, table, attribute, value)
if klass.respond_to?(:blind_indexes) && (bi = klass.blind_indexes[attribute])
- value = BlindIndex.generate_bidx(value, **bi)
attribute = bi[:bidx_attribute]
end
super(klass, table, attribute, value)
end
end