Pow v1.0.20 Pow.Extension.Ecto.Schema View Source
Handles extensions for the user Ecto schema.
The macro will append fields to the @pow_fields
module attribute using the
attributes from [Pow Extension].Ecto.Schema.attrs/1
, so they can be used in
the Pow.Ecto.Schema.pow_user_fields/0
method call.
After module compilation [Pow Extension].Ecto.Schema.validate!/2
will run.
Usage
Configure lib/my_project/users/user.ex
the following way:
defmodule MyApp.Users.User do
use Ecto.Schema
use Pow.Ecto.Schema
use Pow.Extension.Ecto.Schema,
extensions: [PowExtensionOne, PowExtensionTwo]
schema "users" do
pow_user_fields()
timestamps()
end
def changeset(user_or_changeset, attrs) do
user
|> pow_changeset(attrs)
|> pow_extension_changeset(attrs)
end
end
Link to this section Summary
Functions
Merge all extension associations together to one list.
Merge all extension attributes together to one list.
This will run changeset/3
on all extension ecto schema modules.
Merge all extension indexes together to one list.
Validates that the ecto schema has the specified field.
This will run validate!/2
on all extension ecto schema modules.
Link to this section Functions
Merge all extension associations together to one list.
The extension ecto schema modules is discovered through the :extensions
key
in the configuration, and the attribute list will be in the same order as the
extensions list.
Merge all extension attributes together to one list.
The extension ecto schema modules is discovered through the :extensions
key
in the configuration, and the attribute list will be in the same order as the
extensions list.
changeset(changeset, attrs, config)
View Sourcechangeset(Ecto.Changeset.t(), map(), Pow.Config.t()) :: Ecto.Changeset.t()
This will run changeset/3
on all extension ecto schema modules.
The extension ecto schema modules is discovered through the :extensions
key
in the configuration, and the changesets will be piped in the same order
as the extensions list.
Merge all extension indexes together to one list.
The extension ecto schema modules is discovered through the :extensions
key
in the configuration, and the index list will be in the same order as the
extensions list.
Validates that the ecto schema has the specified field.
If the field doesn't exist, it'll raise an exception.
validate!(config, module)
View Sourcevalidate!(Pow.Config.t(), atom()) :: :ok | no_return()
This will run validate!/2
on all extension ecto schema modules.
It's used to ensure certain fields are available, e.g. an :email
field. The
method should either raise an exception, or return :ok
. Compilation will
fail when the exception is raised.