From 7b170b5026e58aa58e441f608181e08612befecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20V=C3=B5hmar?= Date: Tue, 4 Aug 2020 23:09:43 +0300 Subject: [PATCH] Revert "Revert "Domain transfer: remove duplicate domain_contacts on transfer"" --- app/models/concerns/domain/transferable.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/domain/transferable.rb b/app/models/concerns/domain/transferable.rb index 56e77f34d..9de2fff83 100644 --- a/app/models/concerns/domain/transferable.rb +++ b/app/models/concerns/domain/transferable.rb @@ -57,7 +57,8 @@ module Concerns::Domain::Transferable def transfer_domain_contacts(new_registrar) copied_ids = [] - contacts.each do |contact| + domain_contacts.each do |dc| + contact = Contact.find(dc.contact_id) next if copied_ids.include?(contact.id) || contact.registrar == new_registrar if registrant_id_was == contact.id # registrant was copied previously, do not copy it again @@ -66,7 +67,11 @@ module Concerns::Domain::Transferable oc = contact.transfer(new_registrar) end - domain_contacts.where(contact_id: contact.id).update_all({ contact_id: oc.id }) # n+1 workaround + if domain_contacts.find_by(contact_id: oc.id, domain_id: id, type: dc.type).present? + dc.destroy + else + dc.update(contact_id: oc.id) + end copied_ids << contact.id end end