Open hamiltop opened 8 years ago
Purely on syntax, I prefer the second option - I don't know how I feel about a pipe operator inside an argument.
@martimatix Repo.get!(preload(Post, [:comments]), id)
would work just as well.
From slack:
Post |> preload([:comments]) |> Repo.query(query_with_join)
I actually do like that.
I spent a bit of time playing with associations.
Definite steps forward: Use Ecto to manage associations.
has_one
,has_many
,belongs_to
,embeds_one
,embeds_many
, etc. are all very well built and easy to inspect at runtime.Uncertainty: How do we read and write?
Ecto does preloading on reads it via Ecto.Query. We would need an alternative approach.
Read
I see two approaches that could provide this functionality.
Repo.get!(Post |> preload([:comments]), id)
Repo.get!(Post, id, preload: [:comments])
Writes
Ecto.Changeset can handle all the writes just fine. Insert and Update should work exactly like ecto.