From 77d059aace7c2ece7f9b1a556f2695053835400a Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Wed, 7 Feb 2024 11:28:50 -0800 Subject: [PATCH] Fixed aggregate relational queries like `count()` --- src/fields/BaseRelationField.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/fields/BaseRelationField.php b/src/fields/BaseRelationField.php index ae1d3c6c07f..b9c5a80c742 100644 --- a/src/fields/BaseRelationField.php +++ b/src/fields/BaseRelationField.php @@ -702,10 +702,8 @@ public function normalizeValue(mixed $value, ?ElementInterface $element): mixed if ( $this->sortable && !$this->maintainHierarchy && - ( - !$query->orderBy || - (count($query->orderBy) === 1) && ($query->orderBy[0] ?? null) instanceof OrderByPlaceholderExpression - ) + count($query->orderBy ?? []) === 1 && + ($query->orderBy[0] ?? null) instanceof OrderByPlaceholderExpression ) { $q->orderBy(["$relationsAlias.sortOrder" => SORT_ASC]); }