Hi,
I have a User
resource that has many Organizations
. Organizations in turn have many Workgroups. A user can only be part of exactly one workgroup, per organization.
I would like to make it easy to get the workgroup for a specific organization_id for a user.
So I can fetch the user and workgroup easily if I have user_id and organization_id.
I know I can use filter on the relationship, e.g.
user.workgroups |> Ash.Query.filter(organization_id = ^organization_id) |> Ash.read_one!(...)
But I would like to be able to do something like:
User.get_by_id(user_id, load: [ workgroup_for_org:[organization_id: org_id ] ])
I know the answer is probably “Calculations”, but i can’t find any examples of returning Resources from calculations (if that is even possible).
So what I am looking for is something like a parameterized relationship.