View Source Pow.Extension.Ecto.Schema (Pow v1.0.38)

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 function 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

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.

Functions

@spec assocs(Pow.Config.t()) :: [tuple()]

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.

@spec attrs(Pow.Config.t()) :: [tuple()]

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.

Link to this function

changeset(changeset, attrs, config)

View Source
@spec 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.

@spec indexes(Pow.Config.t()) :: [tuple()]

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.

Link to this function

require_schema_field!(module, field, extension)

View Source
@spec require_schema_field!(atom(), atom(), atom()) :: :ok

Validates that the ecto schema has the specified field.

If the field doesn't exist, it'll raise an exception.

Link to this function

validate!(config, module)

View Source
@spec validate!(Pow.Config.t(), atom()) :: :ok

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 function should either raise an exception, or return :ok. Compilation will fail when the exception is raised.