[4.x] Bug in defaultSort
Package
filament/filament
Package Version
v4.0.0-beta4
Laravel Version
v11.45.1
Livewire Version
v3.6.3
PHP Version
PHP 8.3.15
Problem description
Bug report #16516
I've set up the local environment and accessed http://localhost/admin/custom-treatments.
This resulted in the following error:
Even though defaultSort is specified with a custom query, the model's primary key is still being used for an additional sort.
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'treatments.id' in 'order clause'
select
`sub`.`id`,
`sub`.`description`,
`sub`.`name`,
`sub`.`type`
from
(
select
`t`.`id`,
`t`.`description`,
`p`.`name`,
`p`.`type`
from
`treatments` as `t`
inner join `patients` as `p` on `t`.`patient_id` = `p`.`id`
where
`t`.`is_valid` = 1
) as `sub`
order by
`sub`.`name` asc,
`treatments`.`id` asc -- this is unexpect sort
limit
10 offset 0
Even though defaultSort is configured, the table is still sorting by id. This is an unintended bug that didn't occur in v3.
Expected behavior
Ensure http://localhost/admin/custom-treatments loads without errors.
Steps to reproduce
local set up and php artisan migrate:fresh --seed next, access: http://localhost/admin/custom-treatments
Reproduction repository (issue will be closed if this is not valid)
https://github.com/bzy107/filament-select-bug
Relevant log output