Skip to content

Commit 9e03e7e

Browse files
fix: remove duplicate column in sql query on manual sorting (#18626)
* fix: remove duplicate column in sql query on manual sorting * fix: add check between default and normal sort, to avoid duplication in the query --------- Co-authored-by: Giacomo Masseroni <[email protected]>
1 parent b907778 commit 9e03e7e

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

packages/tables/src/Concerns/CanSortRecords.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,11 @@ protected function applySortingToTableQuery(Builder $query): Builder
8585
return $query->orderBy($this->getTable()->getReorderColumn(), $this->getTable()->getReorderDirection());
8686
}
8787

88+
$tableSortColumn = $this->getTableSortColumn();
89+
8890
if (
89-
$this->getTableSortColumn() &&
90-
$column = $this->getTable()->getSortableVisibleColumn($this->getTableSortColumn())
91+
$tableSortColumn &&
92+
$column = $this->getTable()->getSortableVisibleColumn($tableSortColumn)
9193
) {
9294
$sortDirection = $this->getTableSortDirection() === 'desc' ? 'desc' : 'asc';
9395

@@ -99,11 +101,14 @@ protected function applySortingToTableQuery(Builder $query): Builder
99101

100102
if (
101103
is_string($defaultSort) &&
102-
($defaultSort !== $this->getTableSortColumn()) &&
104+
($defaultSort !== $tableSortColumn) &&
103105
($sortColumn = $this->getTable()->getSortableVisibleColumn($defaultSort))
104106
) {
105107
$sortColumn->applySort($query, $sortDirection);
106-
} elseif (is_string($defaultSort)) {
108+
} elseif (
109+
is_string($defaultSort) &&
110+
$defaultSort !== $tableSortColumn
111+
) {
107112
$query->orderBy($defaultSort, $sortDirection);
108113
}
109114

0 commit comments

Comments
 (0)