I am having difficulty loading a relationship in Ash. I have two tables, departments and organizations. The organizations table has a UUID primary key and a unique identity field domain. The departments table has a foreign key organization_id references the organizations table. This is a multi-tenancy setup where the organization is the tenant holder and the strategy is by :context. Multi-tenancy is set to the domain field as the tenant prefix rather than the UUID.
Is there a way to load the relationship using the unique domain field?
get_village = MyAshPhoenixApp.Client.Department.get_by_id!("0715bc32-0b15-4e44-aa23-5df65e8c35eb", tenant: "default", load: :organization)
SELECT v0."id", v0."name", v0."inserted_at", v0."updated_at", v0."organization_id" FROM "default"."departments" AS v0 WHERE (v0."id"::uuid = $1::uuid) ["0715bc32-0b15-4e44-aa23-5df65e8c35eb"]
↳ anonymous fn/3 in AshPostgres.DataLayer.run_query/2, at: lib/data_layer.ex:704
SELECT o0."id", o0."name", o0."domain", o0."go_live_date", o0."is_live", o0."email_domains", o0."inserted_at", o0."updated_at" FROM "organizations" AS o0 WHERE (o0."id"::uuid IN ($1::uuid)) [nil]
↳ anonymous fn/3 in AshPostgres.DataLayer.run_query/2, at: lib/data_layer.ex:704
Note there are two queries executed. The first query fetches the village by id, and the second query tries to fetch the organization by id. The query is expecting an UUID and the value provided is nil. The unique identity “domain” field of the “organizations” table for the prefixes in my multi-tenancy setup.
#MyAshPhoenixApp.Client.Department<
organization: nil, #<<<<<< NOT LOADED
__meta__: #Ecto.Schema.Metadata<:loaded, "default", "departments">,
id: "0715bc32-0b15-4e44-aa23-5df65e8c35eb",
...
>
Is there a way to switch relationship lookup from get_by_id to get_by_domain? Or is there another way to load the relationship using the domain field?
Here are two gist files for my Organization and Department:
organization.ex gist
department.ex gist






















