mirror of
https://github.com/espocrm/espocrm.git
synced 2026-07-01 08:26:04 +00:00
orm order expression fix
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user