Unverified Commit 28d45273 authored by Seamus Lee's avatar Seamus Lee Committed by GitHub

Merge pull request #17134 from jitendrapurohit/core-1723-rc

#1723 - Adv Search - Reciprocal relationship search with custom fields leads to error
parents eb0c07bf 804261ab
......@@ -4191,7 +4191,7 @@ WHERE $smartGroupClause
if (self::$_relType == 'reciprocal') {
$where = [];
self::$_relationshipTempTable = $relationshipTempTable = CRM_Utils_SQL_TempTable::build()
->createWithColumns("`contact_id` int(10) unsigned NOT NULL DEFAULT '0', `contact_id_alt` int(10) unsigned NOT NULL DEFAULT '0', relationship_id int unsigned, KEY `contact_id` (`contact_id`), KEY `contact_id_alt` (`contact_id_alt`)")
->createWithColumns("`contact_id` int(10) unsigned NOT NULL DEFAULT '0', `contact_id_alt` int(10) unsigned NOT NULL DEFAULT '0', id int unsigned, KEY `contact_id` (`contact_id`), KEY `contact_id_alt` (`contact_id_alt`)")
->getName();
if ($nameClause) {
$where[$grouping][] = " sort_name $nameClause ";
......@@ -4207,7 +4207,7 @@ WHERE $smartGroupClause
$groupJoinTable = "contact_b";
$groupJoinColumn = "id";
}
$allRelationshipType = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, NULL, TRUE);
$allRelationshipType = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, NULL, TRUE, 'label', FALSE);
if ($nameClause || !$targetGroup) {
if (!empty($relationType)) {
$relQill = '';
......@@ -4315,7 +4315,7 @@ civicrm_relationship.start_date > {$today}
$whereClause = str_replace('contact_b', 'c', $whereClause);
}
$sql = "
INSERT INTO {$relationshipTempTable} (contact_id, contact_id_alt, relationship_id)
INSERT INTO {$relationshipTempTable} (contact_id, contact_id_alt, id)
(SELECT contact_id_b as contact_id, contact_id_a as contact_id_alt, civicrm_relationship.id
FROM civicrm_relationship
INNER JOIN civicrm_contact c ON civicrm_relationship.contact_id_a = c.id
......
......@@ -658,6 +658,54 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase {
$this->assertEquals($contactID_b, $dao->contact_id, "Search query returns parent of contact A?");
}
/**
* Relationship search with custom fields.
*/
public function testReciprocalRelationshipWithCustomFields() {
$params = [
'extends' => 'Relationship',
];
$customGroup = $this->customGroupCreate($params);
$customFieldId = $this->customFieldCreate(['custom_group_id' => $customGroup['id']])['id'];
$contactID_a = $this->individualCreate();
$contactID_b = $this->individualCreate();
$relationship = $this->callAPISuccess('Relationship', 'create', [
'contact_id_a' => $contactID_a,
'contact_id_b' => $contactID_b,
'relationship_type_id' => 2,
'is_active' => 1,
"custom_{$customFieldId}" => 'testvalue',
]);
$params = [
[
0 => 'relation_type_id',
1 => 'IN',
2 =>
[
0 => '2_a_b',
],
3 => 0,
4 => 0,
],
[
0 => "custom_{$customFieldId}",
1 => '=',
2 => 'testvalue',
3 => 0,
4 => 0,
],
];
$query = new CRM_Contact_BAO_Query($params);
$dao = $query->searchQuery();
$this->assertEquals('2', $dao->N);
$this->callAPISuccess('Relationship', 'delete', ['id' => $relationship['id']]);
$this->callAPISuccess('Contact', 'delete', ['id' => $contactID_a, 'skip_undelete' => 1]);
$this->callAPISuccess('Contact', 'delete', ['id' => $contactID_b, 'skip_undelete' => 1]);
$this->callAPISuccess('CustomField', 'delete', ['id' => $customFieldId, 'skip_undelete' => 1]);
$this->callAPISuccess('CustomGroup', 'delete', ['id' => $customGroup]);
}
/**
* @throws \CRM_Core_Exception
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment