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 896a3b9 commit 68b207b087588fc9a2cc8edb842408e3be5ba9ef @tarmo tarmo committed with NZKoz
Showing with 7 additions and 1 deletion.
  1. +7 −1 activerecord/lib/active_record/validations.rb
View
8 activerecord/lib/active_record/validations.rb
@@ -625,7 +625,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 68b207b

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