CoherenceAssent v0.2.3 CoherenceAssent.Schema View Source

Add CoherenceAssent support to a User schema module.

Add use CoherenceAssent.Schema to your User module to add a number of Module functions and helpers.

The coherence_assent_schema/0 macro is used to add schema fields to the User models schema.

Examples:

defmodule MyProject.User do
  use MyProject.Web, :model

  use Coherence.Schema
  use CoherenceAssent.Schema

  schema "users" do
    field :name, :string
    field :email, :string
    coherence_schema
    coherence_assent_schema
    timestamps
  end

  @required_fields ~w(name email)
  @optional_fields ~w() ++ coherence_fields

  def changeset(model, params \ %{}) do
    model
    |> cast(params, @required_fields, @optional_fields)
    |> unique_constraint(:email)
    |> validate_coherence_assent(params)
  end

  def changeset(model, params, :password) do
    model
    |> cast(params, ~w(password password_confirmation reset_password_token reset_password_sent_at))
    |> validate_coherence_password_reset(params)
  end
end

Link to this section Summary

Functions

Add configure schema fields

Link to this section Functions

Link to this macro coherence_assent_schema() View Source (macro)

Add configure schema fields.