Ecto preload and order in one query with join left

Hi,

I have slider query that preload slides and media images attached to slides.
I would like to order slides by inserted_at, how can I achive that?

Thanks

    Slider
    |> where([slider], slider.id == ^id)
    |> join(:left, [s], _ in assoc(s, :slides))
    |> join(:left, [_, slides], _ in assoc(slides, :media))
    |> preload([_, p, m], [slides: {p, media: m}])
    |> Repo.one!

You can just use a query for that. the documentation for preload has a section for how to use a query with preload.

But I want to have it in one query so I need left join, preload and order…

You should be able to just add an order_by, what issue do you get with that and what is the generated SQL and what do you want the generated SQL to be?