Filtering relationships in `relates_to_actor_via` etc.
Have a number of cases that I'm looking to set up policies and/or filters that perform a deep (but simple) join where for some path components it's necessary to filter the relationship. It's not feasible to create a different relationship for each possible filter, and I wanted to make sure that for right now I'm looking at doing the join manually in a custom check/filter.
Generally would be interested in the current thought process for supporting parameterized relationships, and whether this is one of the target scenarios that's intended to be addressed.
Related:
- https://github.com/orgs/ash-project/projects/3?pane=issue&itemId=10193112
8 Replies
This is one of the many things that would solve, yes. Although parameterized relationships are a very complex topic and also I think start muddying the grounds between calculations and aggregates.
Is it possible at this point to define a relationship as an Ecto query fragment and push it down into the datalayer? My concern is that something like this is heavy enough when it's run as a large set of joins in Postgres, but if I'm defining the path elements that need to be filtered as manual relationships that it's going to bring a ton of data up to the Ash layer to satisfy the query.
This isn't really related to the parameterization per se, but I have had it on my list, and it would be useful for more complex cases such as relationships based on a recursive join.
Yes, you can do that
you'd define a manual relationship, and then use
AshPostgres
tools to define how you join to itRight on 🙂
Thanks!
its a bit verbose and twiddly, but you also get reuse via manual relationships
i.e
And it has to be usable in every situation we might use a relationship. I think we can improve the ergonomics in the future though.
Oh yeah, definitely. I guess there are simply cases where the closest I would come is generating these because of the number of possibilities. Generally what I've had so far are all bounded sets, so it would be possible to have them as individual relationships this way by generating the clauses with a macro/extension, but in some cases the possible set of values is quite large.