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

crm_get_relationships does not return relationships of "a" side

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.4
    • Fix Version/s: 1.5
    • Labels:
      None

      Description

      The following is copied from the CRM dev list:
      ------------
      The bug is that getRelationship($contactID) only works for $contactID iff $contactID is stored as "contact_id_b", if name_a_b does not equal name_b_a. Since "Affiliated organization of" is the B side, and "Affiliated with" is the A side, you can go from the organization to the individual, but not the other way around.

      Since we care more about finding the organization the individual is affiliated than the other way around, the quick work-around is to just swap the A columns with the B columns in both civicrm_relationship_types and civicrm_relationship. This I've confirmed works.

      The doc problem is that crm_get_relationship does not return an object, but an array.

      Rob

      Rob Thorne wrote:
      > To search for all relationships of a contact, it looks to like you'd need to do the following:
      > $rel_name = 'Affiliated with'; $contact = crm_get_contact(array('contact_id' => $contact_id));
      > $all_types = crm_get_relationship_types();
      > foreach ($all_types as $robj)

      { > if (isset($robj->name_a_b) and $robj->name_a_b == $rel_name) > $type_objs[] = $robj; > }

      > }
      > //Docs say this returns an array or null
      > $rslt = crm_get_relationships($contact, NULL, $type_objs);
      >
      >
      > Going through the debugger, I'm not getting any errors, but I'm not finding a single relationship either.
      >
      >
      > But the db has relationships in it, including the following records:
      >
      > mysql> select * from civicrm_relationship where contact_id_a = 4384
      > or contact_id_b = 4384;
      > ----------------------------------------------------------------------------
      > | id | contact_id_a | contact_id_b | relationship_type_id |
      > start_date | end_date | is_active |
      > ----------------------------------------------------------------------------
      > | 915 | 4384 | 75819 | 8 |
      > NULL | NULL | 1 |
      > ----------------------------------------------------------------------------
      > 1 row in set (0.01 sec)
      >
      > and also
      >
      > mysql> select id, name_a_b, name_b_a from civicrm_relationship_type;
      > ---------------------------------------------------
      > | id | name_a_b | name_b_a |
      > ---------------------------------------------------
      > | 1 | Child of | Parent of |
      > | 2 | Spouse of | Spouse of |
      > | 3 | Sibling of | Sibling of |
      > | 4 | Employee of | Employer of |
      > | 5 | Volunteer for | Volunteer is |
      > | 6 | Head of Household for | Head of Household is |
      > | 7 | Household Member of | Household Member is |
      > | 8 | Affiliated with | Affiliated organization of |
      > ---------------------------------------------------
      > 8 rows in set (0.01 sec)
      >
      > It turns out that CRM_Contact_BAO_Relationship::getRelationship($contactID) is finding no relationships for $contact_id == 4384. But if you look at contact 4384 in the CiviCRM UI, you will see that the UI displays that 4384 is affiliated with the right organization.
      >
      > What am I doing wrong here, or do I have a bug in 1.4?
      >
      > Thanks,
      > Rob

        Attachments

          Activity

            People

            • Assignee:
              lobo Donald A. Lobo
              Reporter:
              torenware Rob Thorne
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: