Skip to content

Commit

Permalink
SelectFactory: Select Extra fields only if explicitly selected
Browse files Browse the repository at this point in the history
Fix tests by using `Group` entity instead of `Product` because `Product`
is not in CiviCRM core, anymore.
  • Loading branch information
Dominic Tubach committed Oct 26, 2023
1 parent 2d3a5b8 commit 601ab7b
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 146 deletions.
18 changes: 14 additions & 4 deletions Civi/RemoteTools/Helper/SelectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,29 @@ final class SelectFactory implements SelectFactoryInterface {

/**
* @inheritDoc
*
* phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh
*/
public function getSelects(
array $select,
array $entityFields,
array $remoteFields,
callable $implicitJoinAllowedCallback
): array {
// phpcs:enable
if ([] === $select || in_array('*', $select, TRUE)) {
$rowCountSelected = in_array('row_count', $select, TRUE);
$select = array_filter(
array_keys($remoteFields),
fn (string $fieldName) => !FieldUtil::isJoinedField($fieldName),
);
$select = array_keys(array_filter(
$remoteFields,
// @phpstan-ignore-next-line
fn (array $field) => (!FieldUtil::isJoinedField($field['name'])
// CiviCRM excludes fields of type "Extra" if not explicitly selected,
// see \Civi\Api4\Query\Api4SelectQuery. This includes fields like
// "has_base" for managed entity types which are fetched using a sub
// query.
&& 'Extra' !== ($field['type'] ?? NULL))
|| in_array($field['name'], $select, TRUE),
));
if ($rowCountSelected) {
$select[] = 'row_count';
}
Expand Down
Loading

0 comments on commit 601ab7b

Please sign in to comment.