From 44eead20ca962a201d5c9b43f6a6ee2281bb18e8 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 17 Jun 2021 08:10:19 -0400 Subject: [PATCH] Fix getReferencesToContactTable to ignore non-id references Fixes dev/core#2656 https://lab.civicrm.org/dev/core/-/issues/2656 --- CRM/Core/DAO.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index 181c39a757..253c58d580 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -2591,7 +2591,7 @@ SELECT contact_id * @param string $tableName * Table referred to. * - * @return array + * @return CRM_Core_Reference_Interface[] * structure of table and column, listing every table with a * foreign key reference to $tableName, and the column where the key appears. */ @@ -2628,7 +2628,12 @@ SELECT contact_id $contactReferences = []; $coreReferences = CRM_Core_DAO::getReferencesToTable('civicrm_contact'); foreach ($coreReferences as $coreReference) { - if (!is_a($coreReference, 'CRM_Core_Reference_Dynamic')) { + if ( + // Exclude option values + !is_a($coreReference, 'CRM_Core_Reference_Dynamic') && + // Exclude references to other columns + $coreReference->getTargetKey() === 'id' + ) { $contactReferences[$coreReference->getReferenceTable()][] = $coreReference->getReferenceKey(); } } -- 2.25.1