}
$fieldInfo = \CRM_Utils_Array::value($fieldName, $fkField['FKApiSpec']);
- // FIXME: What if the foreign key is not the "id" column?
- if (!$fieldInfo || !isset($fkField['FKApiSpec']['id'])) {
+ $keyColumn = \CRM_Utils_Array::value('FKKeyColumn', $fkField, 'id');
+ if (!$fieldInfo || !isset($fkField['FKApiSpec'][$keyColumn])) {
// Join doesn't exist - might be another param with a dot in it for some reason, we'll just ignore it.
return NULL;
}
// Add acl condition
$joinCondition = array_merge(
- array("$prev.$fk = $tableAlias.id"),
+ array("$prev.$fk = $tableAlias.$keyColumn"),
$this->getAclClause($tableAlias, \_civicrm_api3_get_BAO($fkField['FKApiName']), $subStack)
);
+ if (!empty($fkField['FKCondition'])) {
+ $joinCondition[] = str_replace($fkTable, $tableAlias, $fkField['FKCondition']);
+ }
+
$this->join($side, $fkTable, $tableAlias, $joinCondition);
if (strpos($fieldName, 'custom_') === 0) {
}
/**
- * Get join info for dynamically-joined fields (e.g. "entity_id")
+ * Get join info for dynamically-joined fields (e.g. "entity_id", "option_group")
*
* @param $fkField
* @param $stack
$fkField['FKApiName'] = \CRM_Core_DAO_AllCoreTables::getBriefName($fkField['FKClassName']);
}
}
+ if (!empty($fkField['pseudoconstant']['optionGroupName'])) {
+ $fkField['FKClassName'] = 'CRM_Core_DAO_OptionValue';
+ $fkField['FKApiName'] = 'OptionValue';
+ $fkField['FKKeyColumn'] = 'value';
+ $fkField['FKCondition'] = "civicrm_option_value.option_group_id = (SELECT id FROM civicrm_option_group WHERE name = '{$fkField['pseudoconstant']['optionGroupName']}')";
+ }
}
/**
$first = 'firstthisisatest';
$last = 'lastthisisatest';
$org = $this->organizationCreate(array('organization_name' => 'Employer of one'));
- $person1 = $this->individualCreate(array('employer_id' => $org, 'first_name' => $first, 'last_name' => $last));
+ $person1 = $this->individualCreate(array('employer_id' => $org, 'first_name' => $first, 'last_name' => $last, 'gender_id' => 1));
$person2 = $this->individualCreate(array(), 1);
$result = $this->callAPISuccessGetSingle('Email', array(
- 'return' => 'contact_id.employer_id.display_name',
+ 'return' => 'contact_id.employer_id.display_name,contact_id.gender_id.label',
'contact_id.last_name' => $last,
'contact_id.first_name' => $first,
));
$this->assertEquals('Employer of one', $result['contact_id.employer_id.display_name']);
+ $this->assertEquals('Female', $result['contact_id.gender_id.label']);
}
}