From: Coleman Watts Date: Wed, 10 Feb 2021 14:53:43 +0000 (-0500) Subject: APIv4 - Fix wildcard expansion in joins X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=a44a39449669480d17042af93a178b44d6d334c9;p=civicrm-core.git APIv4 - Fix wildcard expansion in joins Passing a fake field (e.g. related_entity.*) to autoJoinFk was triggering it to always re-attempt a join, because it could never find a filed named "*". Instead pass it a real field (every entity has an "id"). --- diff --git a/Civi/Api4/Query/Api4SelectQuery.php b/Civi/Api4/Query/Api4SelectQuery.php index 3122d24582..49a3760b31 100644 --- a/Civi/Api4/Query/Api4SelectQuery.php +++ b/Civi/Api4/Query/Api4SelectQuery.php @@ -211,10 +211,12 @@ class Api4SelectQuery { return strpos($item, '*') !== FALSE && strpos($item, '.') !== FALSE && strpos($item, '(') === FALSE && strpos($item, ' ') === FALSE; }); - foreach ($wildFields as $item) { - $pos = array_search($item, array_values($select)); - $this->autoJoinFK($item); - $matches = SelectUtil::getMatchingFields($item, array_keys($this->apiFieldSpec)); + foreach ($wildFields as $wildField) { + $pos = array_search($wildField, array_values($select)); + // If the joined_entity.id isn't in the fieldspec already, autoJoinFK will attempt to add the entity. + $idField = substr($wildField, 0, strrpos($wildField, '.')) . '.id'; + $this->autoJoinFK($idField); + $matches = SelectUtil::getMatchingFields($wildField, array_keys($this->apiFieldSpec)); array_splice($select, $pos, 1, $matches); } $select = array_unique($select);