Does filament add a default orderBy to relation manager queries?

Hi all, I have a simple relation manager but running into this error when its loading:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'name' in 'order clause'
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'name' in 'order clause'
The issue is that I'm not ordering the query at all! I've tried to remove all of the ordering using:
->modifyQueryUsing(fn (Builder $query) => $query->reorder())
->modifyQueryUsing(fn (Builder $query) => $query->reorder())
- https://laravel.com/docs/12.x/queries#removing-existing-orderings but that hasn't worked. Anyone have any ideas as to where the order could be being applied? Thanks
Database: Query Builder - Laravel 12.x - The PHP Framework For Web ...
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
Solution:
Managed to fix this by using
->defaultSort('address_id')
->defaultSort('address_id')
Jump to solution
3 Replies
Harvey
Harvey6d ago
It's likely ordering by $recordTitleAttribute by default. You can set a default sort by doing ->defaultSort('created_at', 'desc') on your $table schema
garethfrost
garethfrostOP6d ago
I've got
protected static ?string $recordTitleAttribute = 'address_id';
protected static ?string $recordTitleAttribute = 'address_id';
which it does order by but for some reason it adds an orderBy on name first, this is the ordering from the error:
ORDER BY
`name` ASC,
`addresses`.`id` ASC
ORDER BY
`name` ASC,
`addresses`.`id` ASC
Solution
garethfrost
garethfrost6d ago
Managed to fix this by using
->defaultSort('address_id')
->defaultSort('address_id')

Did you find this page helpful?