Question on Multitenancy.

I read this doc But few things are not still clear for me. I am trying to add Attribute Multitenancy 1. Should I add multitenancy macro and belongs to :organization to all resources? 2. I noticed we have functions like Ash.Query.set_tenant for read and Ash.Changeset.set_tenant for create. So I don't need to add something like change manage_relationship(:organization_id, :organization, type: :append) for create action?
3 Replies
barnabasj
barnabasj2mo ago
You linked the ecto guide, we have one for Ash as well https://hexdocs.pm/ash/multitenancy.html the attribute should be added to the resource when you add the multientacy block with attribute in the dsl, you only need the orgainztion belongs_to if you want to load it. most of the times you don't need the set_tenant function, you just pass the tenant when creating the query/changeset or pass it to the generated code interface.
Yahya Oxley
Yahya Oxley4w ago
@barnabasj does this mean that we need to sprinkle tenant: socket.assigns.current_tenant all over the app? Is there a way to just say to ash: "from now on use this tenant on everything"?
barnabasj
barnabasj4w ago
You create a scope in a plug to make it a bit more ergonomic, but you do have to keep track of it yourself https://hexdocs.pm/ash/3.5.37/Ash.Scope.html

Did you find this page helpful?