Loading multitenant resources

Given the following action:
read :list_organizations do
prepare build(load: [:establishments])
end
read :list_organizations do
prepare build(load: [:establishments])
end
I'm listing orgs and need to load their child establishments (which have a multitenancy attribute configured via organization_id). It throws an error saying I need to specify a tenant to load the establishments. How would I set the tenant here?
Solution:
```elixir read :list_organizations do prepare build(load: [:establishments]) multitenancy :bypass_all end...
Jump to solution
12 Replies
ZachDaniel
ZachDaniel4mo ago
This is something that we need to add support for but for now you need to roll yourself by bypassing multitenancy in the target action there is a new option, I think we've just released it
Solution
ZachDaniel
ZachDaniel4mo ago
read :list_organizations do
prepare build(load: [:establishments])
multitenancy :bypass_all
end
read :list_organizations do
prepare build(load: [:establishments])
multitenancy :bypass_all
end
ZachDaniel
ZachDaniel4mo ago
try that out
Joan Gavelán
Joan GavelánOP4mo ago
I've upgraded the Ash version to 3.5 and still encountered the error. Maybe I need to upgrade another dep?
Compiling 2 files (.ex)

** (Spark.Error.DslError) [Lamashka.Organizations.Organization]
actions -> read -> list_organizations:
invalid value for :multitenancy option: expected one of [:enforce, :allow_global, :bypass], got: :bypass_all
Compiling 2 files (.ex)

** (Spark.Error.DslError) [Lamashka.Organizations.Organization]
actions -> read -> list_organizations:
invalid value for :multitenancy option: expected one of [:enforce, :allow_global, :bypass], got: :bypass_all
ZachDaniel
ZachDaniel4mo ago
Which version specifically are you on? It was released in 2.5.25
Joan Gavelán
Joan GavelánOP4mo ago
{:ash_authentication_phoenix, "~> 2.10.1"},
{:ash_authentication, "~> 4.0"},
{:ash_postgres, "~> 2.0"},
{:ash_phoenix, "~> 2.3.7"},
{:ash, "~> 3.5"},
{:ash_authentication_phoenix, "~> 2.10.1"},
{:ash_authentication, "~> 4.0"},
{:ash_postgres, "~> 2.0"},
{:ash_phoenix, "~> 2.3.7"},
{:ash, "~> 3.5"},
ZachDaniel
ZachDaniel4mo ago
That's not necesssrily the version you are using mix hex.info ash
Joan Gavelán
Joan GavelánOP4mo ago
mix hex.info ash
A declarative, extensible framework for building Elixir applications.

Config: {:ash, "~> 3.5"}
Locked version: 3.5.23
Releases: 3.5.25, 3.5.24, 3.5.23, 3.5.22, 3.5.21, 3.5.20, 3.5.19, 3.5.18, ...
mix hex.info ash
A declarative, extensible framework for building Elixir applications.

Config: {:ash, "~> 3.5"}
Locked version: 3.5.23
Releases: 3.5.25, 3.5.24, 3.5.23, 3.5.22, 3.5.21, 3.5.20, 3.5.19, 3.5.18, ...
ZachDaniel
ZachDaniel4mo ago
Locked version: 3.5.23
you are not on the latest version mix deps.update ash
Joan Gavelán
Joan GavelánOP4mo ago
Oh you meant 3.5.25 This upgraded it to the latest version! Thanks, now the :bypass_all is available and my read action is loading the relationship Although I'm still getting the DSL error in my editor
** (Spark.Error.DslError) [Lamashka.Organizations.Organization]
actions -> read -> list_organizations:
invalid value for :multitenancy option: expected one of [:enforce, :allow_global, :bypass], got: :bypass_all
(ash 3.5.23) /Users/macbookpro/Work/lamashka/deps/spark/lib/spark/dsl/extension.ex:1198: Ash.Resource.Dsl.Actions.Read.__build__/3
(spark 2.2.66) lib/spark/dsl/extension/entity.ex:91: Spark.Dsl.Extension.Entity.handle/6
lib/lamashka/organizations/organization.ex:40: (module)
(elixir 1.18.3) lib/kernel/parallel_compiler.ex:428: anonymous fn/5 in Kernel.ParallelCompiler.spawn_workers/8 (Elixir)
** (Spark.Error.DslError) [Lamashka.Organizations.Organization]
actions -> read -> list_organizations:
invalid value for :multitenancy option: expected one of [:enforce, :allow_global, :bypass], got: :bypass_all
(ash 3.5.23) /Users/macbookpro/Work/lamashka/deps/spark/lib/spark/dsl/extension.ex:1198: Ash.Resource.Dsl.Actions.Read.__build__/3
(spark 2.2.66) lib/spark/dsl/extension/entity.ex:91: Spark.Dsl.Extension.Entity.handle/6
lib/lamashka/organizations/organization.ex:40: (module)
(elixir 1.18.3) lib/kernel/parallel_compiler.ex:428: anonymous fn/5 in Kernel.ParallelCompiler.spawn_workers/8 (Elixir)
ZachDaniel
ZachDaniel4mo ago
Still shows the old version Elixir LS is weird sometimes 🤷‍♂️
Joan Gavelán
Joan GavelánOP4mo ago
Deleting the .elixir-ls folder and recompiling solved it Thanks Zach!

Did you find this page helpful?