From 3b8b75819a8381495f416ba6eb21f5c5ffd4aa6b Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 15 Jun 2021 15:44:12 -0400 Subject: [PATCH] SearchKit - Fix smart group crash when ordering by aggregated column Fixes dev/report#68 --- CRM/Contact/BAO/GroupContactCache.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CRM/Contact/BAO/GroupContactCache.php b/CRM/Contact/BAO/GroupContactCache.php index c36fb2a1b5..61c40739f0 100644 --- a/CRM/Contact/BAO/GroupContactCache.php +++ b/CRM/Contact/BAO/GroupContactCache.php @@ -530,6 +530,10 @@ ORDER BY gc.contact_id, g.children if (empty($apiParams['having'])) { $apiParams['select'] = array_slice($apiParams['select'], 0, 1); } + // Order is irrelevant unless using limit or offset + if (empty($apiParams['limit']) && empty($apiParams['offset'])) { + unset($apiParams['orderBy']); + } /* @var $api \Civi\Api4\Generic\DAOGetAction */ $api = Request::create($savedSearch['api_entity'], 'get', $apiParams); $query = new Api4SelectQuery($api); -- 2.25.1