aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/validations
diff options
context:
space:
mode:
authorDiego Silva <diego.silva@live.com>2016-02-09 20:46:34 -0200
committerDiego Silva <diego.silva@live.com>2016-02-09 21:28:21 -0200
commitf1daa2be5278bee61dfa9a6dc111b556df677ad8 (patch)
treeaeecaa8c6457c3292f5dbefa981606595ae97586 /activerecord/lib/active_record/validations
parentb5eb2423b6e431ba53e3836d58449e7e810096b4 (diff)
downloadrails-f1daa2be5278bee61dfa9a6dc111b556df677ad8.tar.gz
rails-f1daa2be5278bee61dfa9a6dc111b556df677ad8.tar.bz2
rails-f1daa2be5278bee61dfa9a6dc111b556df677ad8.zip
UniquenessValidator exclude itself when PK changed
When changing the PK for a record which has a uniqueness validation on some other attribute, Active Record should exclude itself from the validation based on the PK value stored on the DB (id_was) instead of its new value (id).
Diffstat (limited to 'activerecord/lib/active_record/validations')
-rw-r--r--activerecord/lib/active_record/validations/uniqueness.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/validations/uniqueness.rb b/activerecord/lib/active_record/validations/uniqueness.rb
index a376e2a17f..f0aa4521b5 100644
--- a/activerecord/lib/active_record/validations/uniqueness.rb
+++ b/activerecord/lib/active_record/validations/uniqueness.rb
@@ -19,7 +19,7 @@ module ActiveRecord
relation = build_relation(finder_class, table, attribute, value)
if record.persisted? && finder_class.primary_key.to_s != attribute.to_s
if finder_class.primary_key
- relation = relation.where.not(finder_class.primary_key => record.id)
+ relation = relation.where.not(finder_class.primary_key => record.id_was)
else
raise UnknownPrimaryKey.new(finder_class, "Can not validate uniqueness for persisted record without primary key.")
end