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
GitHub
Ash Framework Roadmap • ash-project
Ash Framework Roadmap
8 Replies
ZachDaniel
ZachDaniel3y ago
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.
\ ឵឵឵
\ ឵឵឵OP3y ago
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.
ZachDaniel
ZachDaniel3y ago
Yes, you can do that
ZachDaniel
ZachDaniel3y ago
you'd define a manual relationship, and then use AshPostgres tools to define how you join to it
\ ឵឵឵
\ ឵឵឵OP3y ago
Right on 🙂 Thanks!
ZachDaniel
ZachDaniel3y ago
its a bit verbose and twiddly, but you also get reuse via manual relationships i.e
has_many :foo, Foo do
manual {YourThing, :foo}
end

has_many :bar, Bar do
manual {YourThing, :bar}
end
has_many :foo, Foo do
manual {YourThing, :foo}
end

has_many :bar, Bar do
manual {YourThing, :bar}
end
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.
\ ឵឵឵
\ ឵឵឵OP3y ago
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.

Did you find this page helpful?