mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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
This commit is contained in:
parent
2b7f1cdbe9
commit
f1a01c80db
2 changed files with 5 additions and 3 deletions
|
@ -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.]
|
||||
|
|
|
@ -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])
|
||||
|
|
Loading…
Reference in a new issue