ash_postgres/test/support/multitenancy/resources/org.ex

48 lines
815 B
Elixir
Raw Normal View History

2020-10-29 15:26:45 +13:00
defmodule AshPostgres.MultitenancyTest.Org do
@moduledoc false
use Ash.Resource,
data_layer: AshPostgres.DataLayer
resource do
identities do
identity :unique_by_name, [:name]
2020-10-29 15:26:45 +13:00
end
end
attributes do
uuid_primary_key :id
attribute :name, :string
2020-10-29 15:26:45 +13:00
end
actions do
read :read
create :create
update :update
destroy :destroy
2020-10-29 15:26:45 +13:00
end
postgres do
table "multitenant_orgs"
repo AshPostgres.TestRepo
2020-10-29 15:26:45 +13:00
manage_tenant do
template ["org_", :id]
2020-10-29 15:26:45 +13:00
end
end
multitenancy do
strategy :attribute
attribute :id
global? true
parse_attribute {__MODULE__, :tenant, []}
2020-10-29 15:26:45 +13:00
end
relationships do
has_many :posts, AshPostgres.MultitenancyTest.Post, destination_field: :org_id
2020-10-29 15:26:45 +13:00
end
def tenant("org_" <> tenant) do
tenant
end
end