Hi,
I am new to Elixir Phoenix and in the leaning process.
I am trying to implement the apis and have defined multiple schemas with belongs_to, has_one and has_many relations. Following is my controller function.
def show(conn, %{“id” => id}) do
state = GeoData.get_state!(id)
|> Repo.preload([:country, :cities])
# render(conn, "show.json-api", data: state, opts: [include: "cities, country"])
render(conn, "show.json-api", data: state, opts: [include: "country, cities"])
end
I want the GET on http://localhost:4000/api/states to return both country and cities info. However, this renders only cities or country, depending on the order in which I specify them in the render call above. How do I get the API to return both the relations or even more relations as applicable. Whats the syntax to render multiple such relations? Btw, I am able to successfully preload them before rendering and I verified the same with IO.inspect. Its just the rendering part thats failing.
Appreciate any help in this regard.
Thanks,
Rajasekhar.