ExTenant.Changeset (ExTenant v0.2.2) View Source
The function 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, [:name, :body])
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