From 03a69cb364d1e69aae4c659bdf74fb9513041d08 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Thu, 9 Feb 2023 13:01:01 +0200 Subject: [PATCH] ORM use COALESCE --- .../Espo/ORM/QueryComposer/BaseQueryComposer.php | 2 +- tests/unit/Espo/ORM/MapperTest.php | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/application/Espo/ORM/QueryComposer/BaseQueryComposer.php b/application/Espo/ORM/QueryComposer/BaseQueryComposer.php index 0e585d43cf..3fa3a32657 100644 --- a/application/Espo/ORM/QueryComposer/BaseQueryComposer.php +++ b/application/Espo/ORM/QueryComposer/BaseQueryComposer.php @@ -2452,7 +2452,7 @@ abstract class BaseQueryComposer implements QueryComposer $item = $this->getAlias($entity, $relationName) . '.' . $this->toDb($value); $item = $this->quoteColumn($item); - $foreign[$i] = "IFNULL({$item}, '')"; + $foreign[$i] = "COALESCE({$item}, '')"; } $path = 'TRIM(CONCAT(' . implode(', ', $foreign). '))'; diff --git a/tests/unit/Espo/ORM/MapperTest.php b/tests/unit/Espo/ORM/MapperTest.php index 45ea71e936..9fdec6124f 100644 --- a/tests/unit/Espo/ORM/MapperTest.php +++ b/tests/unit/Espo/ORM/MapperTest.php @@ -226,8 +226,8 @@ class MapperTest extends \PHPUnit\Framework\TestCase public function testSelectOne() { $query = - "SELECT post.id AS `id`, post.name AS `name`, NULLIF(TRIM(CONCAT(IFNULL(createdBy.salutation_name, ''), " . - "IFNULL(createdBy.first_name, ''), ' ', IFNULL(createdBy.last_name, ''))), '') AS `createdByName`, ". + "SELECT post.id AS `id`, post.name AS `name`, NULLIF(TRIM(CONCAT(COALESCE(createdBy.salutation_name, ''), " . + "COALESCE(createdBy.first_name, ''), ' ', COALESCE(createdBy.last_name, ''))), '') AS `createdByName`, ". "post.created_by_id AS `createdById`, post.deleted AS `deleted` ". "FROM `post` ". "LEFT JOIN `user` AS `createdBy` ON post.created_by_id = createdBy.id " . @@ -258,8 +258,8 @@ class MapperTest extends \PHPUnit\Framework\TestCase public function testSelect1() { $sql = - "SELECT post.id AS `id`, post.name AS `name`, NULLIF(TRIM(CONCAT(IFNULL(createdBy.salutation_name, ''), " . - "IFNULL(createdBy.first_name, ''), ' ', IFNULL(createdBy.last_name, ''))), '') AS `createdByName`, " . + "SELECT post.id AS `id`, post.name AS `name`, NULLIF(TRIM(CONCAT(COALESCE(createdBy.salutation_name, ''), " . + "COALESCE(createdBy.first_name, ''), ' ', COALESCE(createdBy.last_name, ''))), '') AS `createdByName`, " . "post.created_by_id AS `createdById`, post.deleted AS `deleted` ". "FROM `post` ". "LEFT JOIN `user` AS `createdBy` ON post.created_by_id = createdBy.id " . @@ -520,8 +520,8 @@ class MapperTest extends \PHPUnit\Framework\TestCase { $query = "SELECT ". - "post.id AS `id`, post.name AS `name`, NULLIF(TRIM(CONCAT(IFNULL(createdBy.salutation_name, ''), ". - "IFNULL(createdBy.first_name, ''), ' ', IFNULL(createdBy.last_name, ''))), '') AS `createdByName`, ". + "post.id AS `id`, post.name AS `name`, NULLIF(TRIM(CONCAT(COALESCE(createdBy.salutation_name, ''), ". + "COALESCE(createdBy.first_name, ''), ' ', COALESCE(createdBy.last_name, ''))), '') AS `createdByName`, ". "post.created_by_id AS `createdById`, post.deleted AS `deleted` ". "FROM `post` ". "LEFT JOIN `user` AS `createdBy` ON post.created_by_id = createdBy.id " .