I want to create some Relationships of type "Case Coordinator" via API Call in CiviCRM.
When I create two relationships with the same contact_id_a, relationship_type_id, is_active and case_id values, but with a different contact_id_b value, I nevertheless get the error "Duplicate Relationship thrown in .../public/sites/all/modules/civicrm/api/api.php on line 134".
I have been checking the code in public/sites/all/modules/civicrm/CRM/Contact/BAO/Relationship.php and it seems to check the sameness of contact_id_a and contact_id_b correctly:
public static function checkDuplicateRelationship(&$params, $id, $contactId = 0, $relationshipId = 0) {
...
$queryString .=
" AND ( ( contact_id_a = " . CRM_Utils_Type::escape($id, 'Integer') .
" AND contact_id_b = " . CRM_Utils_Type::escape($contactId, 'Integer') .
" ) OR ( contact_id_a = " . CRM_Utils_Type::escape($contactId, 'Integer') .
" AND contact_id_b = " . CRM_Utils_Type::escape($id, 'Integer') . " ) ) ";
...
}
Only when I add a distinct start_date to the API Create Relationship call, CiviCRM accepts the call and creates the relationship properly.
This is ok as a workaround, but I wonder if anybody knows why the check on Contact A and Contact B in the code is not working here? As obviously two relationships are not a duplicate if they exist between a different pair of contacts.