aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2016-04-27 05:55:32 +0900
committerRyuta Kamizono <kamipo@gmail.com>2016-06-04 23:15:46 +0900
commitaa062318c451512035c10898a1af95943b1a3803 (patch)
treeaa09ae17aced7f28cb45442f247f3c274688e775 /activerecord
parent0ddcade928741886ad2ac1bd0273c3ce28a5e1e1 (diff)
downloadrails-aa062318c451512035c10898a1af95943b1a3803.tar.gz
rails-aa062318c451512035c10898a1af95943b1a3803.tar.bz2
rails-aa062318c451512035c10898a1af95943b1a3803.zip
Avoid type casting in uniqueness validator
Type casting in uniqueness validator is for a string value truncation. It was removed at #23523.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/validations/uniqueness.rb7
1 files changed, 2 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/validations/uniqueness.rb b/activerecord/lib/active_record/validations/uniqueness.rb
index 1f59276137..de8512751a 100644
--- a/activerecord/lib/active_record/validations/uniqueness.rb
+++ b/activerecord/lib/active_record/validations/uniqueness.rb
@@ -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)