How to do order_by by multiple columns in Ecto?

This won’t compile:


items = order_by(MyModel, [desc: :inserted_at, :published_at])
|> Repo.all()

This won’t either:


items = order_by(MyModel, [desc: [:inserted_at, :published_at]])
|> Repo.all()

How?

 order_by(MyModel, [desc: :inserted_at, desc: :published_at])

https://hexdocs.pm/ecto/Ecto.Query.html#order_by/3-keywords-examples

4 Likes