FilamentF
Filament3y ago
John

Filter with recursive relationship

I have organisations that can be of different types. One type is school, which has a relation to a parent organisation, with type foundation.

If I try to add a SelectFilter on School, filtering on parent Foundation, I get a bug in the resulting query. For easy comparing, I added another (non-recursive) filter.

select
    count(*) as aggregate
from
    `org__organisation`
where (
    exists (
        select
            *
        from
            `org__organisation` as `laravel_reserved_0`
        where
            `laravel_reserved_0`.`organisation_id` = `org__organisation`.`elder_id`
            and `org__organisation`.`organisation_id` = '6' # <<<<< THIS IS WRONG
            and `organisation_type_id` = 4 # <<<<< This comes from a global scope, which is correct
    )
    and
    exists (
        select
            *
        from
            `org__subregio`
        where
            `org__organisation`.`subregio_id` = `org__subregio`.`subregio_id`
            and `org__subregio`.`subregio_id` = '3'
    )
)
and `organisation_type_id` = 5


Where is says and org__organisation.organisation_id = '6' it should say and organisation_id = '6' (or alias laravel_reserved_0)

  1. Is this indeed a bug or am I doing it wrong?
  2. If I understand correctly, anything more complex than a simple relation requires a custom Tables\Filters\Filter with a ->form() and a ->query(). Correct?
  3. I created such a custom filter for the recursive relationship. It works beautifully, except it's not showing up in the "Active filters". How can I have it listed there?
Was this page helpful?