Fix getReferencesToContactTable to ignore non-id references
authorColeman Watts <coleman@civicrm.org>
Thu, 17 Jun 2021 12:10:19 +0000 (08:10 -0400)
committerColeman Watts <coleman@civicrm.org>
Thu, 17 Jun 2021 12:10:19 +0000 (08:10 -0400)
Fixes dev/core#2656
https://lab.civicrm.org/dev/core/-/issues/2656

CRM/Core/DAO.php

index 181c39a7579528b6bb216a48e97eae1418aa141d..253c58d580d5d91ac5bba74aa22f223e90b1ffb5 100644 (file)
@@ -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();
       }
     }