Ash FrameworkAF
Ash Framework7mo ago
28 replies
jonas_h

How to load a nested relationship with a tenant?

I'm a beginner with Ash and essentially I'd like to lookup an organization while loading some relationships, something like this:

      Sites.Organization
      |> Ash.Query.load(user_roles: [:user])
      |> Ash.read!()


(I only really need a single organization at the moment but I suppose the question is more general.)

However to load the user roles I have to specify the tenant (which is the organization itself) and I get this error:

Queries against the Guilds.Sites.OrganizationUserRole resource require a tenant to be specified
         at user_roles


How can I load the organization while also loading the relationships that needs the organization itself?

The organization and users live in the "public" schema while the user roles lives in a schema specified by the organization id.

The organization is specified with:

  multitenancy do
    strategy :attribute
    attribute :id
    global? true
  end

  relationships do
    has_many :user_roles, Guilds.Sites.OrganizationUserRole
  end


And the user role:

  multitenancy do
    strategy :context
  end

  relationships do
    belongs_to :organization, Guilds.Sites.Organization do
      primary_key? true
      allow_nil? false
    end

    belongs_to :user, Guilds.Accounts.User do
      primary_key? true
      allow_nil? false
    end
  end
Was this page helpful?