API Reference ExTenant v0.2.4
modules
Modules
Call the use ExTenant
macro to inject all the required behaviour into your
Application Repo module to enable all multi-tenancy functions.
the-function-cast_tenanted-changset-attrs-allowed
The function cast_tenanted(changset, attrs, allowed)
- injects the
tenant_id
key/atom into the allowed fields - retrieves the
tenant_id
value from the process dictionary - injects the %{"tenant_id" => tenant_id} into the attrs map
- and then calls the standard Ecto.Changeset.cast function
An exception will be raised in the following two situations
retrieve the tenanted migrations path using a default fallback
to-use-the-extenant-schema-in-your-schema-modules
To use the Extenant.Schema in your schema modules
- it injects the belongs_to relationship to the tenant
- it also raises a compiler error if the
tenanted()
call was omitted - it works with the
tenant_id
field set in Config.exs
here-is-an-example
Here is an example
defmodule Post do
use ExTenant.Schema
use ExTenant.Changeset
tenanted_schema "posts" do
field(:name, :string)
field(:body, :string)
tenanted()
end
end
utility functions for retrieving the subdomain
from the conn.host
mix-tasks
Mix Tasks
Generates a migration.
Run the tenanted migrations