Preload inside subquery

I’m trying to do some preloading. but in one of the preloads i want to have a order_by and a limit.

This is what i was doing before. Which is pretty straight forward.
Repo.get!(Project, project_id)
|> Repo.preload(pages: [captures: :platform])

Now i wanted to add a query inside it. Everything i tried with adding the platform failed with a bunched of different errors. As i did not find the right implementation yet.
I ended up with this working:
|> preload(pages: [captures: ^from(c in Capture, order_by: [desc: :id], limit: 1)])

But i cannot figure out how to preload the platform. Someone can help me out?

There was a similar question here…

more or less, You would do

sub = from(c in Capture, order_by: [desc: :id], limit: 1)
|> preload(pages: [captures: ^sub])
1 Like