Sorting an Ecto has_many relation
Today I found out that there's an option preload_order in the Ecto.Schema.has_many/3
macro that allow us to configure a sorting field and direction for a relationship. This way we can:
defmodule Post do
use Ecto.Schema
schema "posts" do
has_many :comments, Comment, preload_order: [asc: :title]
end
end
Tweet