Skip to content

Commit

Permalink
Fixed validates_uniqueness_of with decimal columns
Browse files Browse the repository at this point in the history
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
tarmo authored and jeremy committed Aug 15, 2008
1 parent aad7cac commit e3523f1
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions activerecord/lib/active_record/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)}"
Expand Down

0 comments on commit e3523f1

Please sign in to comment.