diff options
author | Arthur Klepchukov <arthur.klepchukov@gmail.com> | 2009-03-07 13:52:17 +0000 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-03-07 13:52:17 +0000 |
commit | ccb0a92fa2ba0bf7be50033090c3a861e6d907be (patch) | |
tree | 6657a66b2c19c3437837f6f2a38672d1b6827953 /activerecord/lib/active_record | |
parent | f36513653fceb01691288dfdebfdc56d17dc85c9 (diff) | |
download | rails-ccb0a92fa2ba0bf7be50033090c3a861e6d907be.tar.gz rails-ccb0a92fa2ba0bf7be50033090c3a861e6d907be.tar.bz2 rails-ccb0a92fa2ba0bf7be50033090c3a861e6d907be.zip |
Ensure validates_uniqueness_of considers limit on the field. [#1042 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/validations.rb | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index 8f3c80565e..4453047daf 100644 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -720,20 +720,20 @@ module ActiveRecord # class (which has a database table to query from). finder_class = class_hierarchy.detect { |klass| !klass.abstract_class? } - is_text_column = finder_class.columns_hash[attr_name.to_s].text? + column = finder_class.columns_hash[attr_name.to_s] if value.nil? comparison_operator = "IS ?" - elsif is_text_column + elsif column.text? comparison_operator = "#{connection.case_sensitive_equality_operator} ?" - value = value.to_s + value = column.limit ? value.to_s[0, column.limit] : value.to_s else comparison_operator = "= ?" end sql_attribute = "#{record.class.quoted_table_name}.#{connection.quote_column_name(attr_name)}" - if value.nil? || (configuration[:case_sensitive] || !is_text_column) + if value.nil? || (configuration[:case_sensitive] || !column.text?) condition_sql = "#{sql_attribute} #{comparison_operator}" condition_params = [value] else |