So looks like you can do it with something like:
# Get products
Repo.all(Product)
# Item from product
Repo.get_by(Item, product_id: product_id)
# Both at the same time
Repo.get(Product, product_id) |> Repo.preload(:items)
# or...
from(
p in Product,
where: p.id == ^product_id,
preload: [:items],
# pagination logic...
)
|> Repo.all()
You can read more about it here: https://hexdocs.pm/ecto/Ecto.Query.html#preload/3
And for your number 2: https://hexdocs.pm/ecto/Ecto.Changeset.html#put_assoc/4 or https://hexdocs.pm/ecto/Ecto.Changeset.html#cast_assoc/3
Here there’s a good article about it: http://blog.plataformatec.com.br/2015/08/working-with-ecto-associations-and-embeds/ and a convo Confussed with build_assoc vs put_assoc vs cast_assoc