I have this code:
q = from p in Case, where: p.user_id == ^user_id:
Repo.all(q)
|> Repo.preload(:helper)
with the view render function:
alias ChatWeb.HelperView
def render("api_case.json", %{case: case, message: message, token: token}) do
%{
status: "1",
token: token.token,
items: case.items,
helpers: render_many(case.helper, HelperView, "helper.json"),
}
end
if I have helper data, everything will be OK.
but if I don't have anything in helper, I will get:
protocol Enumerable not implemented for #Ecto.Association.NotLoaded of type Ecto.Association.NotLoaded (a struct)
How can I resolve this?
render_many(case, ...)instead ofrender_many(case.helper, ...), it's easier to handle if there is no data in association, maybe? - copserhelperassociation (why isn't this calledhelpers?) is not preloaded. Are you sure you're posting/using the correct query? - zwippie