From 55385c8a39117f5c1b78fcb703f9d7ac14d97d12 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Thu, 11 Feb 2016 22:58:18 -0500 Subject: Fix issue #23625 This resolves a bug where if the primary key used is not `id` (ex: `uuid`), and has a `validates_uniqueness_of` in the model, a uniqueness error would be raised. This is a partial revert of commit `119b9181ece399c67213543fb5227b82688b536f`, which introduced this behavior. --- activerecord/lib/active_record/validations/uniqueness.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/validations/uniqueness.rb') diff --git a/activerecord/lib/active_record/validations/uniqueness.rb b/activerecord/lib/active_record/validations/uniqueness.rb index f0aa4521b5..91e565f468 100644 --- a/activerecord/lib/active_record/validations/uniqueness.rb +++ b/activerecord/lib/active_record/validations/uniqueness.rb @@ -17,7 +17,7 @@ module ActiveRecord value = map_enum_attribute(finder_class, attribute, value) relation = build_relation(finder_class, table, attribute, value) - if record.persisted? && finder_class.primary_key.to_s != attribute.to_s + if record.persisted? if finder_class.primary_key relation = relation.where.not(finder_class.primary_key => record.id_was) else -- cgit v1.2.3