Pow v1.0.0-rc.1 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

Link to this function __schema_extensions__(config) View Source
__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.

Link to this function changeset(changeset, attrs, config) View Source

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.

Link to this function require_schema_field!(module, field, extension) View Source
require_schema_field!(atom(), atom(), atom()) :: :ok | no_return()

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