Ecto query order for preload

Hey, I have this query:

recording_query =
  from(
    r in Recording,
    order_by: [desc: r.id],
    where: r.user_id == ^user.id,
    preload: [:user, comment: [:user]],
    select: r
  )

Repo.all(recording_query) 

How can I order the preloaded data? the comments here?

figured it myself:

comment_order_query = from(c in Comment, order_by: c.inserted_at, preload: [:user])

recording_query =
  from(
    r in Recording,
    order_by: [desc: r.id],
    where: r.user_id == ^user.id,
    preload: [:user, comment: ^comment_order_query],
    select: r
  )

Repo.all(recording_query)
6 Likes