From f8eb7679fd9df1989e276494c3fab2d1b2cd68ce Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Sun, 10 Apr 2022 14:27:38 +0300 Subject: [PATCH] fix link multiple order --- application/Espo/Core/ORM/Entity.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/application/Espo/Core/ORM/Entity.php b/application/Espo/Core/ORM/Entity.php index 4b3d3b5e66..aacaea4cf5 100644 --- a/application/Espo/Core/ORM/Entity.php +++ b/application/Espo/Core/ORM/Entity.php @@ -101,7 +101,7 @@ class Entity extends BaseEntity * * @param string $link * @return ?array{ - * orderBy: ?string, + * orderBy: string|array|null, * order: ?string, * } */ @@ -191,14 +191,22 @@ class Entity extends BaseEntity ->getRelation($this, $field) ->select($select); + $orderBy = null; + $order = null; + $orderParams = $this->getRelationOrderParams($field); - if ($orderParams && $orderParams['orderBy']) { - if (!in_array($orderParams['orderBy'], $select)) { - $selectBuilder->select($orderParams['orderBy']); + if ($orderParams) { + $orderBy = $orderParams['orderBy'] ?? null; + $order = $orderParams['order'] ?? null; + } + + if ($orderBy) { + if (is_string($orderBy) && !in_array($orderBy, $select)) { + $selectBuilder->select($orderBy); } - $selectBuilder->order($orderParams['orderBy'], $orderParams['order']); + $selectBuilder->order($orderBy, $order); } $collection = $selectBuilder->find();