View Source Filterable.Phoenix.Model (Filterable v0.7.5)
Allows to extend Ecto model with filterable
macros and functions.
use Filterable.Phoenix.Controller
Example:
defmodule MyApp.PostController do
use MyApp.Web, :controller
use Filterable.Phoenix.Controller
filterable do
filter author(query, value, _conn) do
query |> where(author_name: ^value)
end
end
# /posts?author=Kafka
def index(conn, params) do
with {:ok, query, filter_values} <- apply_filters(Post, conn),
posts <- Repo.all(query),
do: render(conn, "index.json", posts: posts, meta: filter_values)
end
end
Works only for Ecto models in Phoenix app.
Use use Filterable
for Ecto models outside Phoenix app.