Relax.Resource.Fetchable behaviour

A behaviour for fetching models.

Typically brought into your resource via use Relax.Resource.

Types

fetchable :: module | Ecto.Query.t | list

Callbacks

fetchable/1

Specs:

Define the base collection of models to be fetched.

Return a query or collection of models to be used by fetch_all and fetch_one.

# Return all models to be queried.
def fetchable(_conn), do: MyApp.Models.Post

# Return query limited to the current_user to be queried.
def fetchable(conn), do: Ecto.assoc(conn.assigns[:current_user], :posts)

It may also return a list of structs/models:

def fetchable(_conn), do: [%Post{title: "foo"}, %Post{title: "bar"}]