From a44a39449669480d17042af93a178b44d6d334c9 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 10 Feb 2021 09:53:43 -0500 Subject: [PATCH] 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"). --- Civi/Api4/Query/Api4SelectQuery.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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); -- 2.25.1