foreign concat name null if empty
This commit is contained in:
@@ -1401,8 +1401,10 @@ abstract class Base
|
||||
$fieldPath = 'TRIM(CONCAT(' . implode(', ', $foreign). '))';
|
||||
|
||||
if ($wsCount > 1) {
|
||||
$fieldPath = "REPLACE({$fieldPath}, ' ', ' ')";
|
||||
$fieldPath = "REPLACE({$fieldPath}, ' ', ' ')";
|
||||
}
|
||||
|
||||
$fieldPath = "NULLIF({$fieldPath}, '')";
|
||||
} else {
|
||||
$expression = $this->getAlias($entity, $relationName) . '.' . $foreign;
|
||||
$fieldPath = $this->convertComplexExpression($entity, $expression, false, $params);
|
||||
|
||||
@@ -120,7 +120,7 @@ class DBMapperTest extends \PHPUnit\Framework\TestCase
|
||||
public function testSelectById()
|
||||
{
|
||||
$query =
|
||||
"SELECT post.id AS `id`, post.name AS `name`, TRIM(CONCAT(IFNULL(createdBy.salutation_name, ''), IFNULL(createdBy.first_name, ''), ' ', IFNULL(createdBy.last_name, ''))) AS `createdByName`, post.created_by_id AS `createdById`, post.deleted AS `deleted` ".
|
||||
"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.created_by_id AS `createdById`, post.deleted AS `deleted` ".
|
||||
"FROM `post` ".
|
||||
"LEFT JOIN `user` AS `createdBy` ON post.created_by_id = createdBy.id " .
|
||||
"WHERE post.id = '1' AND post.deleted = '0'";
|
||||
@@ -140,7 +140,7 @@ class DBMapperTest extends \PHPUnit\Framework\TestCase
|
||||
public function testSelect()
|
||||
{
|
||||
$query =
|
||||
"SELECT post.id AS `id`, post.name AS `name`, TRIM(CONCAT(IFNULL(createdBy.salutation_name, ''), IFNULL(createdBy.first_name, ''), ' ', IFNULL(createdBy.last_name, ''))) AS `createdByName`, post.created_by_id AS `createdById`, post.deleted AS `deleted` ".
|
||||
"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.created_by_id AS `createdById`, post.deleted AS `deleted` ".
|
||||
"FROM `post` ".
|
||||
"LEFT JOIN `user` AS `createdBy` ON post.created_by_id = createdBy.id " .
|
||||
"JOIN `post_tag` AS `tagsMiddle` ON post.id = tagsMiddle.post_id AND tagsMiddle.deleted = '0' ".
|
||||
@@ -290,7 +290,7 @@ class DBMapperTest extends \PHPUnit\Framework\TestCase
|
||||
public function testSelectRelatedBelongsTo()
|
||||
{
|
||||
$query =
|
||||
"SELECT post.id AS `id`, post.name AS `name`, TRIM(CONCAT(IFNULL(createdBy.salutation_name, ''), IFNULL(createdBy.first_name, ''), ' ', IFNULL(createdBy.last_name, ''))) AS `createdByName`, post.created_by_id AS `createdById`, post.deleted AS `deleted` ".
|
||||
"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.created_by_id AS `createdById`, post.deleted AS `deleted` ".
|
||||
"FROM `post` ".
|
||||
"LEFT JOIN `user` AS `createdBy` ON post.created_by_id = createdBy.id " .
|
||||
"WHERE post.id = '1' AND post.deleted = '0' ".
|
||||
|
||||
Reference in New Issue
Block a user