From 68b207b087588fc9a2cc8edb842408e3be5ba9ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tarmo=20T=C3=A4nav?= Date: Thu, 31 Jul 2008 19:26:18 +0300 Subject: Cast value to string in validates_uniqueness_of if the column is of text type This fixes an error for postgresql where "text_column = 100" fails in version 8.3 Signed-off-by: Michael Koziarski --- activerecord/lib/active_record/validations.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index b957ee3b9e..52f674847e 100755 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -625,7 +625,13 @@ module ActiveRecord # 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 -- cgit v1.2.3