"Advanced" filtering best practices

Hi everyone!

I’m working with a Supabase backend that has a hierarchy of information with several levels, each with a foreign key reference to the level above it. I have RLS policies in place to restrict user access based on the uppermost level, so that handles security. The rest is more about convenience/UX.

To that end, in WeWeb I am trying to filter my collections to narrow down the data that’s loaded. Filtering table 2 items based on a value pulled from table 1 is trivial as table 2 has a “parent item from table 1” property. Things get trickier for levels below that, though. Say I want to filter table 3 items based on their relationship to table 1 via table 2 - how do I do that in WeWeb? i.e. if I only want to show items from table 3 that are related to items from table 2 that are themselves related to the value pulled from table 1? And what about the next level under that (table 4)?

Table 1
Table 2
Table 3
Table 4

It feels like in the filtering menu for the table 3 collection I should be able to specify “parent table 2 item” IS IN “table 2” collection, but that’s not an option here:

It seems if I try to fetch more than one property from a foreign key relation (in this case I am fetching the “parent table 2 item” UUID and name), the filtering element treats the foreign key as an array with no option to specify just one property from that array, and restricts the filtering operator options accordingly. Is that a bug, or am I doing this wrong?

Any help would be appreciated :pray:

That is currently a limitation of WeWeb.

Interesting, thank you. So my options are to further filter on the back end with RLS rules or load everything and filter on the front end?

I’d suggest tapping into the exposed SDK instance, or filter via the advanced settings, but that’s a terrible experience. You can check out the Postgrest docs, if you want to try that out.

I thought I was already filtering using the advanced settings, is there another way to filter collections in WeWeb? Otherwise I was thinking, could Supabase views help here?

Yes, if you don’t have very dynamic filters, then I’d definitely go for views. You can also sort of filter via the Advanced fields, but it’s not an optimal experience. Or you can access the SDK instance that WeWeb exposes, and do the calls from there.

Just to clarify, are you talking about these Advanced fields in the configuration menu?

image

If so, how does filtering work in there?

https://postgrest.org/en/stable/references/api/resource_embedding.html#embedded-filters
These docs should apply)

Ahhhh thank you!