F
Filament11mo ago
CT

Expected behaviour or bug? Global ->orderBy() scope not being respected by Filament Tables

I have many models that are each sorted using a global scope. The global scope remains, but it is the secondary orderBy as Filament always sets a default orderBy. For example here is the query with the global scope: SELECT * FROM categories ORDER BY categories.id ASC, name ASC LIMIT 50 OFFSET 0 and here it is without the global scope: SELECT * FROM categories ORDER BY categories.id ASC LIMIT 50 OFFSET 0 The problem I can see is that if ->defaultSort() on the table is undefined or even if ->defaultSort(null) is set then inside of vendor/filament/tables/src/Concerns/CanSortRecords.php we have this line here: return $query->orderBy($query->getModel()->getQualifiedKeyName()); So that means every query is always sorted by the model's key. Of course I can simply run ->defaultSort('name') and that will solve it, but with dozens of models this seems kind of redundant and unnecessary considering I've already setup the global scopes? As per the FilamentPHP docs: By default, Filament will observe all global scopes that are registered to your model. However, this may not be ideal if you wish to access, for example, soft deleted records. which i would argue is not entirely accurate if model global scopes are being overridden. To me it seems strange that 1) we are always setting a default orderBy and 2) it also seems strange that setting null on the orderBy continues to set an orderBy. Is this expected behavior or a bug? I'm happy to submit a PR but just wanted to check first I am not missing something obvious. Thanks.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server