Last active
May 2, 2024 19:22
-
-
Save michaelwa/938c636c2b24d653b95c414035c88707 to your computer and use it in GitHub Desktop.
department.ex gist for multitenant
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
making this change allowed me to return the "domain" in the Repo.all_tenants call.