Skip to content
Browse files

Cast value to string in validates_uniqueness_of if the column is of t…

…ext type

This fixes an error for postgresql where "text_column = 100" fails in version 8.3

Signed-off-by: Michael Koziarski <michael@koziarski.com>
  • Loading branch information...
1 parent e6bc5c6 commit 6d8d77e3ced9c12478591f8af8590f40c73a2593 @tarmo tarmo committed Jul 31, 2008
Showing with 7 additions and 1 deletion.
  1. +7 −1 activerecord/lib/active_record/validations.rb
View
8 activerecord/lib/active_record/validations.rb
@@ -618,7 +618,13 @@ def validates_uniqueness_of(*attr_names)
# class (which has a database table to query from).
finder_class = class_hierarchy.detect { |klass| !klass.abstract_class? }
- if value.nil? || (configuration[:case_sensitive] || !finder_class.columns_hash[attr_name.to_s].text?)
+ is_text_column = finder_class.columns_hash[attr_name.to_s].text?
+
+ if !value.nil? && is_text_column
+ value = value.to_s
+ end
+
+ if value.nil? || (configuration[:case_sensitive] || !is_text_column)
condition_sql = "#{record.class.quoted_table_name}.#{attr_name} #{attribute_condition(value)}"
condition_params = [value]
else

0 comments on commit 6d8d77e

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