diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-10-31 00:33:51 -0200 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-12-18 08:35:03 -0200 |
commit | 23750b4733e1d8e7ef334d70998258d1d2e2c6c8 (patch) | |
tree | b7cb31332c9ea7748ff684feacced7127c0e8cd5 /activerecord | |
parent | 73fb6349c98742bb404bd7ad97184d19f32a8366 (diff) | |
download | rails-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.rb | 16 |
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 |