CRM-5646 Problem with relationship API if all contacttypes

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Major
    • Resolution: Fixed/Completed
    • Affects Version/s: 3.0.2
    • Fix Version/s: 3.0.4
    • Component/s: CiviCRM API
    • Labels:
      None

      Description

      The relationship API returns an error if I try to establish a relation between an individual and an organization when the setup is All contacttypes.
      I have set up a relationship type called Partner (see attachment) with All Contacttypes.

      When I use the following code to add a relationship I get an error (Contact ID :3315 is not of contact type).
      Code:
      $params = array(
      'contact_id_a' => 3315,
      'contact_id_b' => 3314,
      'relationship_type_id' => 30,
      'start_date' => date("Y-m-d", strtotime("2010-01-14")),
      'is_active' => 1);

      // Call CiviCRM API functie to add relation:

      $rel = & civicrm_relationship_create( $params );

      /* write error if civicrm returns error */
      print_r($rel);

      The error disappears if I change the setup of the relationship to From Person To Organization. But I need this type as well between Organizations, and I assume this should work.

        Attachments

          Activity

          [CRM-5646] Problem with relationship API if all contacttypes
          Erik Hommel added a comment -

          Set up of relationship type

          Erik Hommel added a comment -

          Fixed it by changing this code in v2/Relationship.php (function _civicrm_relationship_format_params)

          if ($relation['contact_type_a'] != CRM_Contact_BAO_Contact::getContactType($params['contact_id_a'])) {
          return civicrm_create_error("Contact ID :{$params['contact_id_a']} is not of contact type {$relation['contact_type_a']}");
          }
          if ($relation['contact_type_b'] != CRM_Contact_BAO_Contact::getContactType($params['contact_id_b'])) {
          return civicrm_create_error("Contact ID :{$params['contact_id_b']} is not of contact type {$relation['contact_type_b']}");
          }

          into:
          if (!empty($relation['contact_type_a'])) {

          if ($relation['contact_type_a'] != CRM_Contact_BAO_Contact::getContactType($params['contact_id_a'])) {
          return civicrm_create_error("Contact ID :{$params['contact_id_a']} is not of contact type {$relation['contact_type_a']}");
          }
          }
          if (!empty($relation['contact_type_b'])) {

          if ($relation['contact_type_b'] != CRM_Contact_BAO_Contact::getContactType($params['contact_id_b'])) {
          return civicrm_create_error("Contact ID :{$params['contact_id_b']} is not of contact type {$relation['contact_type_b']}");
          }
          }

          Deepak Srivastava added a comment -

          fixed in r25922.

          Rajan P Mayekar added a comment -

          Tested in r25922.

            People

            • Assignee:
              Rajan P Mayekar
              Reporter:
              Erik Hommel

              Dates

              • Created:
                Updated:
                Resolved: