From 725a91cb00964958c267b73da455f8f8b1d3b9f4 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Tue, 22 Dec 2020 12:19:38 +1100 Subject: [PATCH] [APIv4] Permit using other SQL functions such as CONCAT within a GROUP_CONCAT --- Civi/Api4/Query/SqlFunctionGROUP_CONCAT.php | 2 +- tests/phpunit/api/v4/Action/SqlFunctionTest.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Civi/Api4/Query/SqlFunctionGROUP_CONCAT.php b/Civi/Api4/Query/SqlFunctionGROUP_CONCAT.php index b683f15a72..fb618e0ac7 100644 --- a/Civi/Api4/Query/SqlFunctionGROUP_CONCAT.php +++ b/Civi/Api4/Query/SqlFunctionGROUP_CONCAT.php @@ -24,7 +24,7 @@ class SqlFunctionGROUP_CONCAT extends SqlFunction { [ 'prefix' => ['', 'DISTINCT', 'ALL'], 'expr' => 1, - 'must_be' => ['SqlField'], + 'must_be' => ['SqlField', 'sqlFunction'], 'optional' => FALSE, ], [ diff --git a/tests/phpunit/api/v4/Action/SqlFunctionTest.php b/tests/phpunit/api/v4/Action/SqlFunctionTest.php index 0ff7f2cec1..27815be6c3 100644 --- a/tests/phpunit/api/v4/Action/SqlFunctionTest.php +++ b/tests/phpunit/api/v4/Action/SqlFunctionTest.php @@ -76,6 +76,18 @@ class SqlFunctionTest extends UnitTestCase { $this->assertTrue(4 === $agg['count']); $this->assertContains('Donation', $agg['GROUP_CONCAT:financial_type_id:name']); + + // Test GROUP_CONCAT with a CONCAT as well + $agg = Contribution::get(FALSE) + ->addGroupBy('contact_id') + ->addWhere('contact_id', '=', $cid) + ->addSelect("GROUP_CONCAT(CONCAT(financial_type_id, ', ', contact_id, ', ', total_amount))") + ->addSelect('COUNT(*) AS count') + ->execute() + ->first(); + + $this->assertTrue(4 === $agg['count']); + $this->assertContains('1, ' . $cid . ', 100.00', $agg['GROUP_CONCAT:financial_type_id_contact_id_total_amount']); } public function testGroupHaving() { -- 2.25.1