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

Updating relationship gives sometimes wrong duplicate relationship result

    Details

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

      Description

      When you create / update a relationship there is a test to see if the relationship already exists.
      public static function checkDuplicateRelationship inside CRM_Contact_BAO_Relationship
      This returns the wrong result under some conditions.

      To reproduce create two relationships between person X and person Y with a diiferent start / end date.
      If you now update one of those relations through the api, with only the id specified ( for example civicrm_api3('Relationship', 'create', array('id' => 'id'
      , is_active => '0') ) you'll get a duplicate relation error.
      This is because inside CRM_Contact_BAO_Relationship::checkDuplicateRelationship the date's only get added to the query, when they're specified in the given params. (see if (array_key_exists($dateField, $params)) line 865). If you omit those, they're not specified in the resulting query which causes the result query to see the other relation as a duplicate.

      I can work around this by specifiing the dates expliciltly when updating a contact through the api.
      civicrm_api3('Relationship', 'create', array('id' => 'id'
      'start_date' => date
      'end_date => 'date
      , is_active => '0')

      I'm not sure how this should be solved best. My guess would be to pre-escape the duplicate test when an id is explicitly given, since then we always update, and don't need to check to avoid a duplicate creation.
      I'll try a PR.

        Attachments

          Activity

            People

            • Assignee:
              atif.shaikh Atif Shaikh
              Reporter:
              mallezie Tim Mallezie
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: