-
Type:
Task
-
Resolution: Unresolved
-
Priority:
Unknown
-
None
-
Affects Version/s: None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Filament sorts a table column configured with counts(), avg(), sum(), min(), max() or exists() by ordering on the withCount-style alias. Our aggregates from PHPLARA-225 are hydrated after the documents are read, so orderBy('animals_count') throws by design. Filament offers this hook instead (filamentphp/filament#20442):
public function orderByRelationAggregate(string $relation, string|Expression $column, string $function, string $direction = 'asc', ?Closure $callback = null): static
$function is one of avg, count, exists, max, min, sum; $column is * for count/exists; $callback constrains the related query first. Implement with one $lookup (PHPLARA-281) plus $addFields ($size, $gt [$size, 0], $sum/$avg/$min/$max over the looked-up array) and a computed-field sort on the pipeline from the Query\Builder ticket. Must be a real public method; macros are not detected.
Filament feature this enables: sortable relationship aggregate columns (TextColumn::make('animals_count')>counts('animals')>sortable() and the other five functions, including the 'relation as alias' => Closure form).
- depends on
-
PHPLARA-283 Filament support: let Query\Builder carry aggregation stages and fold find/count into one pipeline
-
- In Code Review
-
- related to
-
PHPLARA-292 SPIKE: Investigate Filament support
-
- Closed
-