# \#sort

**URL:** https://forum.elixirforum.com/tag/sort/446.md

[Latest](https://forum.elixirforum.com/latest.md) · [Categories](https://forum.elixirforum.com/categories.md) · [Tags](https://forum.elixirforum.com/tags.md)

---

## [How do I sort in descending order on a related resource using Ash.Sort.expr\_sort?](https://forum.elixirforum.com/t/how-do-i-sort-in-descending-order-on-a-related-resource-using-ash-sort-expr-sort/68191)

<div class="topic-metadata">

**Author:** [@kamaroly](https://forum.elixirforum.com/u/kamaroly)\
**Replies:** 2\
**Last updated:** [December 17, 2024, 1:31pm UTC](https://forum.elixirforum.com/t/how-do-i-sort-in-descending-order-on-a-related-resource-using-ash-sort-expr-sort/68191 "2024-12-17T13:31:53Z")

</div>

I need to sort records based on a field in a related resource, but I am not sure how to indicate that it should be in descending mode. Here’s the query I am currently using: Person |\> Ash.Query.filter(user\_id …

---

## [Pagination not working properly with timestamps](https://forum.elixirforum.com/t/pagination-not-working-properly-with-timestamps/61655)

<div class="topic-metadata">

**Author:** [@drikanius](https://forum.elixirforum.com/u/drikanius)\
**Replies:** 5\
**Last updated:** [February 14, 2024, 4:08pm UTC](https://forum.elixirforum.com/t/pagination-not-working-properly-with-timestamps/61655 "2024-02-14T16:08:53Z")

</div>

I have a resource that uses pagination and also sort by inserted\_at Until version 2.18 it worked fine even using timestamps(). Currently I’m on master and I noticed that pagination only works properly when I use timesta…

---

## [Enum.sort\_by to sort a record set (i.e. a list of maps) based on 2 "columns"](https://forum.elixirforum.com/t/enum-sort-by-to-sort-a-record-set-i-e-a-list-of-maps-based-on-2-columns/25972)

<div class="topic-metadata">

**Author:** [@fireproofsocks](https://forum.elixirforum.com/u/fireproofsocks)\
**Replies:** 3\
**Last updated:** [October 10, 2019, 9:45pm UTC](https://forum.elixirforum.com/t/enum-sort-by-to-sort-a-record-set-i-e-a-list-of-maps-based-on-2-columns/25972 "2019-10-10T21:45:51Z")

</div>

I found José’s useful response to how to sort a list of maps by a column. I’m not following how to expand this into sorting by multiple columns. For example, given the following “record set”: records = \[ %{age: 6,…

---

## [Sort with complex conditions](https://forum.elixirforum.com/t/sort-with-complex-conditions/24700)

<div class="topic-metadata">

**Author:** [@hscspring](https://forum.elixirforum.com/u/hscspring)\
**Replies:** 5\
**Last updated:** [August 16, 2019, 9:47am UTC](https://forum.elixirforum.com/t/sort-with-complex-conditions/24700 "2019-08-16T09:47:28Z")

</div>

The task is something below: Given a list of items, each item with a directory and a create\_time, my task is to sort those items by two rules: first rule: a given index\_dict, only contains part of the items. second ru…

---

## [How to implement complexed custom sort?](https://forum.elixirforum.com/t/how-to-implement-complexed-custom-sort/17985)

<div class="topic-metadata">

**Author:** [@ndac\_todoroki](https://forum.elixirforum.com/u/ndac_todoroki)\
**Replies:** 11\
**Last updated:** [November 19, 2018, 8:55pm UTC](https://forum.elixirforum.com/t/how-to-implement-complexed-custom-sort/17985 "2018-11-19T20:55:54Z")

</div>

Thinking of implementing a Chess game in Elixir, I created a module which will represent a chess piece as a struct. defmodule Piece do alias \_\_MODULE\_\_, as: Piece @piece\_types ~w(King Queen Rook Bishop Knight Pawn)a…

---

## [How to sort list of structs based on value in stucts](https://forum.elixirforum.com/t/how-to-sort-list-of-structs-based-on-value-in-stucts/17798)

<div class="topic-metadata">

**Author:** [@benonymus](https://forum.elixirforum.com/u/benonymus)\
**Replies:** 6\
**Last updated:** [November 8, 2018, 3:40pm UTC](https://forum.elixirforum.com/t/how-to-sort-list-of-structs-based-on-value-in-stucts/17798 "2018-11-08T15:40:33Z")

</div>

Hey I have a list of structs like these: %App.Accounts.Event{ \_\_meta\_\_: #Ecto.Schema.Metadata\<:loaded, "events"\>, datetime: ~D\[2018-12-17\], description: "hehexd", id: 10, inserted\_at: ~N\[2018-11-07 0…

---

## [Nested items in Ecto, sorting](https://forum.elixirforum.com/t/nested-items-in-ecto-sorting/13785)

<div class="topic-metadata">

**Author:** [@Darim](https://forum.elixirforum.com/u/Darim)\
**Replies:** 1\
**Last updated:** [April 21, 2018, 7:28am UTC](https://forum.elixirforum.com/t/nested-items-in-ecto-sorting/13785 "2018-04-21T07:28:15Z")

</div>

I have Category and it has many articles. I want to load a Category from a db and sort Articles in it based on “inserted\_at” date of an Article. ctg = Repo.get(Category, 123) |\> Repo.preload(\[article: :mmedia\_en…
