I'm trying to paginate data that has preloaded associations.
In my controller this works:
def index(conn, _params) do
products = Product
|> Repo.all
|> Repo.preload(:category)
render(conn, "index.html", products: products)
end
And this also works:
def index(conn, params) do
{products, kerosene} = Product
|> Repo.paginate(params)
render(conn, "index.html", products: products, kerosene: kerosene)
end
But combining them produces argument error on line |> Repo.paginate(params)
def index(conn, params) do
{products, kerosene} = Product
|> Repo.all
|> Repo.preload(:category)
|> Repo.paginate(params)
render(conn, "index.html", products: products, kerosene: kerosene)
end
If I drop line |> Repo.all it produces:
no function clause matching in Ecto.Repo.Preloader.preload/4" on line |> Repo.preload(:category)