© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
12 replies
John

Filter with recursive relationship

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

If I try to add a
SelectFilter
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
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'
and org__organisation.organisation_id = '6'
it should say
and organisation_id = '6'
and organisation_id = '6'
(or alias
laravel_reserved_0
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
Tables\Filters\Filter
with a
->form()
->form()
and a
->query()
->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?
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Display Table info with Recursive Relationship
FilamentFFilament / ❓┊help
2y ago
multiple relationships with ->relationship()
FilamentFFilament / ❓┊help
3y ago
Table filter with a relationship like so?
FilamentFFilament / ❓┊help
3y ago