Details
-
Type: Bug
-
Status: Done/Fixed
-
Priority: Minor
-
Resolution: Fixed/Completed
-
Affects Version/s: 4.3.2
-
Fix Version/s: 4.4.0
-
Component/s: None
-
Labels:None
Description
Steps to reproduce:
1. Search... > Search Builder
2. Query using Membership Type and any of the operators =, !=, or IN and select a membership type known to have members.
In the test example I created against my own installation I chose contacts that were in a group and also with a Basic Member membership type. The pseudo SQL displayed back to the user in the browser is:
Contacts = Volunteer AND Group Status - "Added" ...AND...
Membership Type = 1
When I turned on debugging and found the relevant SQL query that was generated:
$Query = string(727) "
SELECT DISTINCT UPPER(LEFT(contact_a.sort_name, 1)) as sort_name
FROM civicrm_contact contact_a
LEFT JOIN civicrm_group_contact `civicrm_group_contact-1` ON contact_a.id = `civicrm_group_contact-1`.contact_id
LEFT JOIN civicrm_membership ON civicrm_membership.contact_id = contact_a.id
LEFT JOIN civicrm_contribution_recur ccr ON ( civicrm_membership.contribution_recur_id = ccr.id )
LEFT JOIN civicrm_membership_type ON civicrm_membership.membership_type_id = civicrm_membership_type.id
WHERE ( ( `civicrm_group_contact-1`.group_id = ( 1 )
AND `civicrm_group_contact-1`.status IN ("Added")
AND civicrm_membership_type.name = '1' ) )
AND (contact_a.is_deleted = 0)
ORDER BY UPPER(LEFT(contact_a.sort_name, 1)) asc "
The erroneous condition is:
AND civicrm_membership_type.name = '1'
This compares a varchar(128) column to an integer. I believe it's comparing civicrm_membership_type.name and civicrm_membership.membership_type_id when it should be comparing civicrm_membership_type.id and civicrm_membership.membership_type_id. Or it should be comparing civicrm_membership_type.name to a string from the String Builder.
A more thorough look explaination can be found in the community forums where I troubleshot the issue initially:
http://forum.civicrm.org/index.php?topic=28700.0