Skip to content

Instantly share code, notes, and snippets.

@michaelwa
michaelwa / department.ex
Last active May 2, 2024 19:22
department.ex gist for multitenant
defmodule MyAshPhoenixApp.Client.Department do
use Ash.Resource,
domain: MyAshPhoenixApp.Client,
data_layer: AshPostgres.DataLayer
multitenancy do
strategy :attribute # ----->>>>>> causes warning
attribute :id
# attribute :domain
end
@michaelwa
michaelwa / organization.ex
Last active May 2, 2024 19:05
Elixir Organization for multitenant
defmodule MyAshPhoenixApp.Client.Organization do
use Ash.Resource,
domain: MyAshPhoenixApp.Client,
data_layer: AshPostgres.DataLayer
defimpl Ash.ToTenant do
# %{:domain => _, :id => _, _ => _}
# def to_tenant(resource, %MyAshPhoenixApp.Client.Organization{id: id}) do ## ----->>>>> this line causes a compilation error
def to_tenant(resource, %{:domain => domain, :id => id}) do ## ---->>>> this line creates a warning
if Ash.Resource.Info.data_layer(resource) == AshPostgres.DataLayer