Relax.Resource.PermittedParams behaviour

Summary

filter(conn, opts)

Filters the JSONAPI attributes and relationships based on keyword list

Functions

filter(conn, opts)

Filters the JSONAPI attributes and relationships based on keyword list

Callbacks

permitted_attributes/2

Specs:

  • permitted_attributes(atom, Plug.Conn.t) :: [atom]

A while list of attributes (as atoms) to be merged to params.

First argument is either :create or :update, dependeing on what action is being called.

Examples:

def permitted_attributes(:create, _conn), do: [:title, :slug, :body]

def permitted_attributes(_, conn) do
  if conn.assigns[:current_user].admin? do
    [:email, :password, :admin]
  else
    [:email, :password]
  end
end
permitted_relations/2

Specs:

  • permitted_relations(atom, Plug.Conn.t) :: [atom]

A while list of relations (as atoms) to be merged to params.

First argument is either :create or :update, dependeing on what action is being called.

Relationships each have _id added to the end during formatting.

Example:

def premitted_relations(:create, _conn), do: [:category, :author]
def premitted_relations(:update, _conn), do: [:category]