Skip to content

doc: add code example for context multitenancy #2075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions documentation/topics/advanced/multitenancy.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ In Ash, there are two primary strategies for implementing multitenancy. The firs
## Attribute Multitenancy

```elixir
defmodule MyApp.Users do
defmodule MyApp.Accounts.User do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't propose it as an edit here, but let's change the organization reference below to MyApp.Accounts.Organization. Just more idiomatic Ash naming.

use Ash.Resource, ...

multitenancy do
Expand Down Expand Up @@ -124,9 +124,25 @@ User

## Context Multitenancy

```elixir
defmodule MyApp.Projects.Project do
use Ash.Resource, data_layer: AshPostgres.DataLayer

multitenancy do
strategy :context
end

...

relationships do
belongs_to :organization, MyApp.Accounts.Organization
end
end
```

Context multitenancy allows for the data layer to dictate how multitenancy works. For example, a csv data layer might implement multitenancy via saving the file with different suffixes, or an API wrapping data layer might use different subdomains for the tenant.

For `AshPostgres` context multitenancy, which uses postgres schemas and is referred to ash "Schema Based Multitenancy", see the [guide](https://hexdocs.pm/ash_postgres/schema-based-multitenancy.html)
For `AshPostgres` context multitenancy, which uses Postgres schemas and is referred to Ash "Schema Based Multitenancy", see the [guide](https://hexdocs.pm/ash_postgres/schema-based-multitenancy.html)

## Possible Values for tenant

Expand Down
Loading