From ecd6964fd8bd2ca38efb528e15c8fd309937d07f Mon Sep 17 00:00:00 2001 From: Asher Cerka <83976948+ACerka-Springbuk@users.noreply.github.com> Date: Mon, 24 Jul 2023 12:29:58 -0400 Subject: [PATCH] APP-3029 Fixes prune duplicates. All records with a nil primary key get their primary key replaced by a new object, which will never compare true to anything else. (#28) --- lib/active_record/merge_all.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/active_record/merge_all.rb b/lib/active_record/merge_all.rb index 634d40cc..352b9cb3 100644 --- a/lib/active_record/merge_all.rb +++ b/lib/active_record/merge_all.rb @@ -80,7 +80,10 @@ def do_prune_duplicates end @merges = merges.reverse merges.uniq! do |merge| - primary_keys.map { |key| merge[key] } + # Map the primary keys to determine uniqueness. If a primary key is nil, return a new empty object to + # guarantee a unique value. We don't ever want to throw out records that have a nil primary key as these are + # new records. + primary_keys.map { |key| merge[key].nil? ? Object.new : merge[key] } end merges.reverse! end