Skip to content

Commit

Permalink
Fixed that validates_uniqueness_of used 'id' instead of defined prima…
Browse files Browse the repository at this point in the history
…ry key #406

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@328 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Jan 4, 2005
1 parent 5ac11f2 commit f8bc7a4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*

* Fixed that validates_uniqueness_of used 'id' instead of defined primary key #406

* Fixed that the overwritten respond_to? method didn't take two parameters like the original #391

* Added HasManyAssociation#count that works like Base#count #413 [intinig]
Expand Down
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/validations.rb
Expand Up @@ -213,9 +213,9 @@ def validates_uniqueness_of(*attr_names)

for attr_name in attr_names
if scope = configuration[:scope]
class_eval(%(validate %{errors.add('#{attr_name}', '#{configuration[:message]}') if self.class.find_first(new_record? ? ['#{attr_name} = ? AND #{scope} = ?', #{attr_name}, #{scope}] : ["#{attr_name} = ? AND id <> ? AND #{scope} = ?", #{attr_name}, id, #{scope}])}))
class_eval(%(validate %{errors.add('#{attr_name}', '#{configuration[:message]}') if self.class.find_first(new_record? ? ['#{attr_name} = ? AND #{scope} = ?', #{attr_name}, #{scope}] : ["#{attr_name} = ? AND \#{primary_key} <> ? AND #{scope} = ?", #{attr_name}, id, #{scope}])}))
else
class_eval(%(validate %{errors.add('#{attr_name}', '#{configuration[:message]}') if self.class.find_first(new_record? ? ['#{attr_name} = ?', #{attr_name}] : ["#{attr_name} = ? AND id <> ?", #{attr_name}, id])}))
class_eval(%(validate %{errors.add('#{attr_name}', '#{configuration[:message]}') if self.class.find_first(new_record? ? ['#{attr_name} = ?', #{attr_name}] : ["#{attr_name} = ? AND \#{primary_key} <> ?", #{attr_name}, id])}))
end
end
end
Expand Down

0 comments on commit f8bc7a4

Please sign in to comment.