From f1a01c80dba9dd6545063d8f66ec299ea8f33b8c Mon Sep 17 00:00:00 2001 From: Marcel Molina Date: Fri, 13 Jan 2006 01:51:45 +0000 Subject: Disambiguate table names for columns in validates_uniquness_of's WHERE clause. Closes #3423. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3402 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/validations.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'activerecord/lib') diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index a7e7bd1f26..27ca8d37d1 100755 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -496,17 +496,17 @@ module ActiveRecord configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash) validates_each(attr_names,configuration) do |record, attr_name, value| - condition_sql = "#{attr_name} #{attribute_condition(value)}" + condition_sql = "#{record.class.table_name}.#{attr_name} #{attribute_condition(value)}" condition_params = [value] if scope = configuration[:scope] Array(scope).map do |scope_item| scope_value = record.send(scope_item) - condition_sql << " AND #{scope_item} #{attribute_condition(scope_value)}" + condition_sql << " AND #{record.class.table_name}.#{scope_item} #{attribute_condition(scope_value)}" condition_params << scope_value end end unless record.new_record? - condition_sql << " AND #{record.class.primary_key} <> ?" + condition_sql << " AND #{record.class.table_name}.#{record.class.primary_key} <> ?" condition_params << record.send(:id) end if record.class.find(:first, :conditions => [condition_sql, *condition_params]) -- cgit v1.2.3