Skip to content
Browse files

Disambiguate table names for columns in validates_uniquness_of's WHER…

…E clause. Closes #3423.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3402 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 2b7f1cd commit f1a01c80dba9dd6545063d8f66ec299ea8f33b8c Marcel Molina committed Jan 13, 2006
Showing with 5 additions and 3 deletions.
  1. +2 −0 activerecord/CHANGELOG
  2. +3 −3 activerecord/lib/active_record/validations.rb
View
2 activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Disambiguate table names for columns in validates_uniquness_of's WHERE clause. #3423 [alex.borovsky@gmail.com]
+
* .with_scope imposed create parameters now bypass attr_protected [Tobias Luetke]
* Don't raise an exception when there are more keys than there are named bind variables when sanitizing conditions. [Marcel Molina Jr.]
View
6 activerecord/lib/active_record/validations.rb
@@ -496,17 +496,17 @@ def validates_uniqueness_of(*attr_names)
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])

0 comments on commit f1a01c8

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