Ecto.Model.Callbacks

Parsed documentation:
View on GitHub
Define module-level callbacks in models.

A callback is invoked by your `Ecto.Repo` before (or after)
particular events. Callbacks receive changesets, must
always return a changeset back and always run inside a transaction.

Callbacks in Ecto are useful for data consistency, like keeping
counters, setting field values and so on. For this reason, callbacks
cannot abort and are invoked after the data is validated.

Therefore, don't use callbacks for validation, enforcing business
rules or performing actions unrelated to the data itself, like
sending e-mails.

Finally keep in mind callbacks are not invoked on bulk actions
such as `Ecto.Repo.update_all/3` or `Ecto.Repo.delete_all/2`.

## Example

    defmodule User do
      use Ecto.Model.Callbacks

      after_insert Stats, :increase_user_count

      def increase_user_count(changeset)
        # ...
      end
    end

When creating the user, the `after_insert` callbacks will be
invoked with a changeset as argument. Multiple callbacks
can be defined, they will be invoked in order of declaration.

A callback can be defined in the following formats:

    # Invoke the local function increase_user_count
    after_insert :increase_user_count

    # Invoke the local function increase_user_count
    # with the given arguments (changeset is prepended)
    after_insert :increase_user_count, ["foo", "bar"]

    # Invoke the remote function increase_user_count
    after_insert Stats, :increase_user_count

    # Invoke the remote function increase_user_count
    # with the given arguments (changeset is prepended)
    after_insert Stats, :increase_user_count, ["foo", "bar"]
No suggestions.
Please help! Open an issue on GitHub if this assessment is incorrect.