View Source ExTeal.Resource.Records behaviour (ExTeal v0.27.0)

Provides the records/1 callback used for querying records to be served.

This is typically the base query that you expose, often scoped to the current user.

This behaviour is used by the following ExTeal.Resource actions:

  • ExTeal.Resource.Index
  • ExTeal.Resource.Show
  • ExTeal.Resource.Update
  • ExTeal.Resource.Delete

It relies on (and uses):

  • ExTeal.Resource.Model

Summary

Callbacks

Used to get the base query of records.

Used to specify which relationships to always preload with all requests.

Callbacks

@callback records(Plug.Conn.t(), module()) :: Plug.Conn.t() | Ecto.Queryable.t()

Used to get the base query of records.

Many/most resources will override this:

def records(%Plug.Conn{assigns: %{user_id: user_id}}) do
  model()
  |> where([p], p.author_id == ^user_id)
end

Return value should be %Plug.Conn{} or an %Ecto.Queryable{}.

@callback with() :: [atom()]

Used to specify which relationships to always preload with all requests.

Functions