orm order expression fix

This commit is contained in:
Yuri Kuznetsov
2021-07-24 11:01:55 +03:00
parent 0c6f8bb52d
commit 622cf46858
2 changed files with 22 additions and 1 deletions

View File

@@ -2048,7 +2048,7 @@ abstract class BaseQueryComposer implements QueryComposer
protected function getAttributePathForOrderBy(Entity $entity, string $orderBy, array $params): ?string
{
if (strpos($orderBy, '.') !== false || strpos($orderBy, ':') !== false) {
if (Util::isComplexExpression($orderBy)) {
return $this->convertComplexExpression(
$entity,
$orderBy,

View File

@@ -36,6 +36,7 @@ use Espo\ORM\{
QueryBuilder,
EntityManager,
MetadataDataProvider,
Query\Part\Expression,
};
use Espo\ORM\Query\{
@@ -1097,6 +1098,26 @@ class MysqlQueryComposerTest extends \PHPUnit\Framework\TestCase
$this->assertEquals($expectedSql, $sql);
}
public function testOrderByExpression3()
{
$select = $this->queryBuilder
->select()
->from('Article')
->distinct()
->select(['id'])
->order(Expression::create('1'), 'DESC')
->build();
$expectedSql =
"SELECT DISTINCT article.id AS `id` " .
"FROM `article` WHERE article.deleted = 0 ".
"ORDER BY 1 DESC";
$sql = $this->query->compose($select);
$this->assertEquals($expectedSql, $sql);
}
public function testOrderBy2()
{
$select = $this->queryBuilder