View Source ExTenant.Changeset (ExTenant v0.2.4)
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
- if the
Repo
was not set in the Config.exs file - if the tenant_id in the process dictionary is nil
here-is-an-example
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
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
Example
def changeset(attrs) do
%__MODULE__{}
|> cast_tenanted(attrs, [:name, :body])
end