aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-10-31 00:33:51 -0200
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-12-18 08:35:03 -0200
commit23750b4733e1d8e7ef334d70998258d1d2e2c6c8 (patch)
treeb7cb31332c9ea7748ff684feacced7127c0e8cd5 /activerecord
parent73fb6349c98742bb404bd7ad97184d19f32a8366 (diff)
downloadrails-23750b4733e1d8e7ef334d70998258d1d2e2c6c8.tar.gz
rails-23750b4733e1d8e7ef334d70998258d1d2e2c6c8.tar.bz2
rails-23750b4733e1d8e7ef334d70998258d1d2e2c6c8.zip
Simplify value logic by always typecasting
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/validations/uniqueness.rb16
1 files changed, 5 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/validations/uniqueness.rb b/activerecord/lib/active_record/validations/uniqueness.rb
index dc07645732..5700350cf9 100644
--- a/activerecord/lib/active_record/validations/uniqueness.rb
+++ b/activerecord/lib/active_record/validations/uniqueness.rb
@@ -67,22 +67,16 @@ module ActiveRecord
end
column = klass.columns_hash[attribute.to_s]
-
- if !value.nil? && column.text? && column.limit
- value = value.to_s[0, column.limit]
- else
- value = klass.connection.type_cast(value, column)
- end
+ value = klass.connection.type_cast(value, column)
+ value = value.to_s[0, column.limit] if value && column.limit && column.text?
if !options[:case_sensitive] && value && column.text?
# will use SQL LOWER function before comparison, unless it detects a case insensitive collation
- relation = klass.connection.case_insensitive_comparison(table, attribute, column, value)
+ klass.connection.case_insensitive_comparison(table, attribute, column, value)
else
- value = klass.connection.case_sensitive_modifier(value) unless value.nil?
- relation = table[attribute].eq(value)
+ value = klass.connection.case_sensitive_modifier(value) unless value.nil?
+ table[attribute].eq(value)
end
-
- relation
end
end