ExportXMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Filament's query builder filter has a number constraint on a relationship attribute with an aggregate ("animals where the sum of health check weights >= 300"). Its SQL fallback builds a correlated subquery with selectRaw("cast(sum(...))") and whereRaw("(...toSql()) >= ?"), which throws on MongoDB. Filament offers this hook instead (filamentphp/filament#20442):

      public function whereRelationAggregate(string $relation, string $column, string $function, string $operator, float $value, ?Closure $callback = null): static
      

      $function is avg, max, min or sum; $operator is the SQL comparison operator chosen in the UI. Reuse the $lookup + $addFields field from orderByRelationAggregate() and add a $match on it, mapping =, !=, <>, <, <=, >, >= to their $eq/$ne/$lt/... counterparts. Pagination counts must include the match.

      Filament feature this enables: NumberConstraint::make('healthChecks.weight_kg') with an aggregate in the QueryBuilder table filter.

              Assignee:
              Unassigned
              Reporter:
              Pauline Vos
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated: