ExTenant.Changeset (ExTenant v0.1.5) View Source
##cast_tenanted(changset, attrs, allowed)
- injects the
tenant_idkey/atom into the allowed fields - retrieves the
tenant_idvalue 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
- if the
Repowas not set in the Config.exs file - if the tenant_id in the process dictionary is nil
##Here is an example
defmodule Post do
use ExTenant.Schema
use ExTenant.Changeset
...
defp changeset(attrs) do
%__MODULE__{}
|> cast_tenanted(params, [:field1, :field1])
end
end
Link to this section Summary
Functions
Basically call this like the standard cast function and the module
macros will handle all the tenant_id injecting
Link to this section Functions
Basically call this like the standard cast function and the module
macros will handle all the tenant_id injecting
### example
def changeset(attrs) do
%__MODULE__{}
|> cast_tenanted(attrs, [:name, :body])
end