Ecto get results of preload queries separately?

If I have a schema like: Posts has many Comments has many Users

Ecto will run three queries when preloading comments and users for a single post.

  • Select Post
  • Select all Comments with in Post
  • Select all Users with in Comments

Ecto preload puts the Comments in the %Post{ comments: [ %Comment{} | ... ] }

Is there another Ecto command instead of preload that can get the list of unique comments and users for the Post without merging them into Post?

I want to send the front-end these and make connecting in the front-end.

  • %Post{} with a list of comment ids.
  • a list of %Comment{} each having a list of user ids
  • a list of %User{} each with a list of comment ids


post = Repo.get Post, 1
comments= Repo.all Ecto.assoc(post, :comments)