Skip to content
Browse files

Fixed validates_uniqueness_of with decimal columns

Only use special case-sensitive comparison operators for text columns in
validates_uniqueness_of as mysql can fail at decimal comparisons with
the BINARY operator.
  • Loading branch information...
1 parent aad7cac commit e3523f1d33c3cf53f1a65e520be5e937e9c68c1d @tarmo tarmo committed with jeremy Aug 15, 2008
Showing with 4 additions and 5 deletions.
  1. +4 −5 activerecord/lib/active_record/validations.rb
View
9 activerecord/lib/active_record/validations.rb
@@ -629,12 +629,11 @@ def validates_uniqueness_of(*attr_names)
if value.nil?
comparison_operator = "IS ?"
- else
+ elsif is_text_column
comparison_operator = "#{connection.case_sensitive_equality_operator} ?"
-
- if is_text_column
- value = value.to_s
- end
+ value = value.to_s
+ else
+ comparison_operator = "= ?"
end
sql_attribute = "#{record.class.quoted_table_name}.#{connection.quote_column_name(attr_name)}"

0 comments on commit e3523f1

Please sign in to comment.
Something went wrong with that request. Please try again.