Skip to content

Instantly share code, notes, and snippets.

@michaelwa
Last active May 2, 2024 19:22
Show Gist options
  • Save michaelwa/938c636c2b24d653b95c414035c88707 to your computer and use it in GitHub Desktop.
Save michaelwa/938c636c2b24d653b95c414035c88707 to your computer and use it in GitHub Desktop.
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
postgres do
table "departments"
repo MyAshPhoenixApp.Repo
end
code_interface do
define :create, action: :create
define :read_all, action: :read
define :update, action: :update
define :destroy, action: :destroy
define :get_by_id, args: [:id], action: :by_id
end
actions do
# Exposes default built in actions to manage the resource
defaults [:read, :destroy]
create :create do
# accept name as input
accept [:name]
end
update :update do
# accept name as input
accept [:name]
end
read :by_id do
argument :id, :uuid, allow_nil?: false
get? true
multitenancy :enforce
filter expr(id == ^arg(:id))
end
end
attributes do
uuid_primary_key :id
attribute :name, :string do
allow_nil? false
end
timestamps()
end
relationships do
belongs_to :organization, MyAshPhoenixApp.Client.Organization
end
end
@michaelwa
Copy link
Author

michaelwa commented Apr 26, 2024

making this change allowed me to return the "domain" in the Repo.all_tenants call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment