I'm looking at the Ecto manual for the many-to-many schema function.
I want to get a list of recipes and include all of the tags that they are associated with. I'm using this to retrieve them
def list_recipes do
Repo.all(Recipe) |> Repo.preload(:tags)
end
I'm using the Phoenix framework and the the boiler-plate from mix phx.gen.json
to display it, like this:
def render("index.json", %{recipes: recipes}) do
%{data: render_many(recipes, RecipeView, "recipe.json")}
end
I know that I am retrieving the tags correctly (checked in iex
), but they don't get returned in the json obviously because they're not included in the boilerplate template/view.
What is the best way to modify the boilerplate view/template to include the tags in the index of recipes? Are there any good examples of how to do this?