Sort Ecto Query Results Ordered by Nested Association

An API with multiple endpoints, where you could create an endpoint and drop in which fields can be / should be ordered / filtered by…

It’s worked well so far, these nested associations are irksome though.

I have found an API in Ecto which looks similar to what I need, just not available for order_by:

from(city in City, preload: :country, select: struct(city, [:country_id, :name, country: [:id, :population]]))

Instead you use it to specify fields to return..