1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Avoid type casting in uniqueness validator

Type casting in uniqueness validator is for a string value truncation.
It was removed at #23523.
This commit is contained in:
Ryuta Kamizono 2016-04-27 05:55:32 +09:00
parent 0ddcade928
commit aa062318c4

View file

@ -32,6 +32,7 @@ module ActiveRecord
record.errors.add(attribute, :taken, error_options)
end
rescue RangeError
end
protected
@ -65,8 +66,6 @@ module ActiveRecord
column = klass.columns_hash[attribute_name]
cast_type = klass.type_for_attribute(attribute_name)
value = cast_type.serialize(value)
value = klass.connection.type_cast(value)
comparison = if !options[:case_sensitive] && !value.nil?
# will use SQL LOWER function before comparison, unless it detects a case insensitive collation
@ -77,11 +76,9 @@ module ActiveRecord
if value.nil?
klass.unscoped.where(comparison)
else
bind = Relation::QueryAttribute.new(attribute_name, value, Type::Value.new)
bind = Relation::QueryAttribute.new(attribute_name, value, cast_type)
klass.unscoped.where(comparison, bind)
end
rescue RangeError
klass.none
end
def scope_relation(record, table, relation)