Pow v0.1.0-alpha.4 Pow.Extension.Ecto.Schema View Source
Handles extensions for the user Ecto schema.
The macro will append attributes to the :pow_fields
module attribute, and
run validate!/2
when compilation is done.
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
Fetches all existing Ecto.Schema modules in the extensions
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
__schema_extensions__(Pow.Config.t()) :: [atom()]
Fetches all existing Ecto.Schema modules in the extensions.
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(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!(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.