How can I create a relationship between Duplicate Merged Records?

In my SuiteCRM contacts module I have a custom reference field used on communications which is an auto-number. I have a custom data import process which queries the database to find contact ID’s by my reference and pass these with bulk data updates/inserts.

During merging of duplicates using the interface, I have to pick one or the other of my reference numbers, I cannot retain both, therefore am forced to keep my references on both the live record and deleted duplicate.

What I really need is a way to create a relationship between two contact records when they are merged, such that I can query the live records and deleted duplicates for my reference number and where a reference belongs to a deleted record, use the (duplicate) relationship to find the active contact record and return that records ID.

I appreciate that such a relationship might not be useful in the front end application, in the database it would solve my problem.
Does anyone know of a way I can intercept/enhance the duplicate merge function to generate a new relationship between the deduplicated records?

My knowledge of PHP isn’t hot, but I expect there is a simple way of performing an insert on a relationship table based on the primary record and the deleted duplicate to relate them?