Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 4.7.12, 4.7.15
    • Fix Version/s: None
    • Component/s: CiviCRM Search
    • Labels:
    • Versioning Impact:
      None (no code merged)
    • Documentation Required?:
      None
    • Funding Source:
      Needs Funding
    • Verified?:
      No

      Description

      Got really stumped on this today. I was creating a view, to list contacts, and included phone fields (number + a second one for extension). Contacts with multiple phone numbers were replicated multiple times.

      I figured I would use a "relationship" and point all fields to the same relationship. That still doesn't work. (see screenshot ).

      Ultimately, I ended up specifying a criteria for every field, and this ended up working, but generates rather inefficient SQL.

      LEFT JOIN {civicrm_phone} civicrm_phone ON civicrm_contact.id = civicrm_phone.contact_id AND civicrm_phone.is_primary = :views_join_condition_0
      LEFT JOIN {civicrm_address} civicrm_address ON civicrm_contact.id = civicrm_address.contact_id AND civicrm_address.is_primary = :views_join_condition_1
      LEFT JOIN {civicrm_email} civicrm_email ON civicrm_contact.id = civicrm_email.contact_id AND civicrm_email.is_primary = :views_join_condition_2
      LEFT JOIN {civicrm_phone} civicrm_phone2 ON civicrm_contact.id = civicrm_phone2.contact_id AND civicrm_phone2.is_primary = :views_join_condition_3
      LEFT JOIN {civicrm_phone} civicrm_phone3 ON civicrm_contact.id = civicrm_phone3.contact_id AND civicrm_phone3.is_primary = :views_join_condition_4
      

      After banging my head for a few hours, to try & get this to work properly, I gave up on an efficient configuration, and settled on just replicating my join clauses.

      Steps To Reproduce
      ================

      1. Have a contact with 5 phone numbers, only one of which is primary.
      2. Create a Drupal view.
      3. Add Fields Contact Id, Phone
      4. Save, Run Search, see contact appears 5 times (expected).
      5. Create a relationship (Phone, only selecting primary)
      6. Go back and edit "Phone" field and associate to "Phone" relationship
      7. Save, Run Search

      After fixing it, it should be expected that it works, and that only one contact is shown, in step #7.

      Expected Results.
      In step #7, only one contact is shown.

      Actual Results
      In step #7, the contact continues to appear 5 times. Clearing caches, etc has no impacts, and an independent Drupal module to inspect the query generated by the view shows the redundant (and erroneous joins). See above.

      Workaround
      Don't count on "Phone" relationship, and replicate relationship definition for every field used.

      Note, this problem also happens for address fields. In my case I was using City, State, Country.

      Priority
      Debated between minor & major. Settled no major, because ultimately this makes it easy for user error, and likely for "bad report / data" decisions.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              litespeedmarc Marc Brazeau
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 2 days
                2d
                Remaining:
                Remaining Estimate - 2 days
                2d
                Logged:
                Time Spent - Not Specified
                Not Specified