Permalink
Browse files

Simplify value logic by always typecasting

  • Loading branch information...
1 parent 73fb634 commit 23750b4733e1d8e7ef334d70998258d1d2e2c6c8 @carlosantoniodasilva carlosantoniodasilva committed Oct 31, 2012
Showing with 5 additions and 11 deletions.
  1. +5 −11 activerecord/lib/active_record/validations/uniqueness.rb
@@ -67,22 +67,16 @@ def build_relation(klass, table, attribute, value) #:nodoc:
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

0 comments on commit 23750b4

Please sign in to comment.