Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-16282

SQL error when updating relationship

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Trivial
    • Resolution: Duplicate
    • Affects Version/s: 4.6
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Documentation Required?:
      None

      Description

      When editing the value of a custom field i get following error (in some cases).

      CRM_Core_Exception: unknown relationship create error DB Constraint Violation - possibly contact_id_a should possibly be marked as mandatory for this API. If so, please raise a bug report in /home/mallezie/websites/chirocivi/sites/all/modules/civicrm/CRM/Contact/Form/Relationship.php on line 439

      Debugging the error code, this seems to be an SQL-error generated inside CRM_Contact_DAO_Relationship
      public static function isDeleteRelatedMembership

      Following Query gets run:
      $recordsFound = (int) CRM_Core_DAO::singleValueQuery("SELECT COUNT FROM civicrm_relationship WHERE relationship_type_id IN ( " . implode(',', $relTypeIds) . " ) AND contact_id_a IN ( %1 ) OR contact_id_b IN ( %1 ) AND id IN (" . implode(',', $relIds) . ")", $relParamas);

      However this has a syntax error since in my situation '$relTypeIds' is empty.
      I'm not sure how to reproduce this on the demo-site, but i assume this happens when you edit a relation between pers X and onrg Y while there is also a membership of pers X and org Y of a type which is unrelated to the relationship between the two.

      I'm also getting DuplicateException when trying to update this relation through the api, however i'm not sure that's related. I'll submit a PR for a fix for this problem, if i'll find a fix for the duplicate problem, i'll add it to the same PR.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              mallezie Tim Mallezie
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: