This join was named contact instead of entity_id. Joins that don't match the field name are deprecated
in APIv4 so the old join has been marked as such. Renaming the join fixes SearchKit ability to join
from a custom entity to the parent record.
'links' => [],
];
foreach ($table->getTableLinks() as $link) {
- if (!$link->isDeprecated()) {
+ if (!$link->isDeprecatedBy()) {
$item['links'][] = $link->toArray();
}
}
return;
}
}
- if ($link->isDeprecated()) {
+ if ($link->isDeprecatedBy()) {
$deprecatedAlias = $link->getAlias();
- \CRM_Core_Error::deprecatedWarning("Deprecated join alias '$deprecatedAlias' used in APIv4 get. Should be changed to '{$deprecatedAlias}_id'");
+ \CRM_Core_Error::deprecatedWarning("Deprecated join alias '$deprecatedAlias' used in APIv4 {$this->getEntity()} join to $joinEntity. Should be changed to '{$link->isDeprecatedBy()}'.");
}
$virtualField = $link->getSerialize();
$baseTableAlias = $joinTreeNode['#table_alias'];
/**
* @var bool
*/
- protected $deprecated = FALSE;
+ protected $deprecatedBy = FALSE;
/**
* @param $targetTable
/**
* @return bool
*/
- public function isDeprecated() {
- return $this->deprecated;
+ public function isDeprecatedBy() {
+ return $this->deprecatedBy;
}
/**
- * @param bool $deprecated
- *
+ * @param string|null $deprecatedBy
* @return $this
*/
- public function setDeprecated(bool $deprecated = TRUE) {
- $this->deprecated = $deprecated;
+ public function setDeprecatedBy(string $deprecatedBy = NULL) {
+ $this->deprecatedBy = $deprecatedBy ?? $this->alias . '_id';
return $this;
}
$customTable = $map->getTableByName($tableName);
if (!$customTable) {
$customTable = new Table($tableName);
+ // Add entity_id join from multi-record custom group to the
+ if (!empty($fieldData->is_multiple)) {
+ $newJoin = new Joinable($baseTable->getName(), $customInfo['column'], 'entity_id');
+ $customTable->addTableLink('entity_id', $newJoin);
+ // Deprecated "contact" join name
+ $oldJoin = new Joinable($baseTable->getName(), $customInfo['column'], AllCoreTables::convertEntityNameToLower($entityName));
+ $oldJoin->setDeprecatedBy('entity_id');
+ $customTable->addTableLink('entity_id', $oldJoin);
+ }
}
$map->addTable($customTable);
$links[$alias]['isMultiple'] = !empty($fieldData->is_multiple);
$links[$alias]['columns'][$fieldData->name] = $fieldData->column_name;
- // Add backreference
- if (!empty($fieldData->is_multiple)) {
- $joinable = new Joinable($baseTable->getName(), $customInfo['column'], AllCoreTables::convertEntityNameToLower($entityName));
- $customTable->addTableLink('entity_id', $joinable);
- }
-
if ($fieldData->data_type === 'EntityReference' && isset($fieldData->fk_entity)) {
$targetTable = self::getTableName($fieldData->fk_entity);
$joinable = new Joinable($targetTable, 'id', $fieldData->name);
$this->hookClass->setHook('civicrm_aclWhereClause', [$this, 'aclWhereOnlyOne']);
$this->cleanupCachedPermissions();
- $customValues = CustomValue::get($group)->addSelect('*', 'contact.first_name')->execute();
+ $customValues = CustomValue::get($group)->addSelect('*', 'entity_id.first_name')->execute();
$this->assertCount(1, $customValues);
$this->assertEquals($c2, $customValues[0]['entity_id']);
- $this->assertEquals('C2', $customValues[0]['contact.first_name']);
+ $this->assertEquals('C2', $customValues[0]['entity_id.first_name']);
$customValues = Contact::get()
->addJoin('Custom_' . $group . ' AS cf')