Sorting/order by in related records defined by has_many

Thank you! I actually figured out the syntax and posted it in this related post:

For preloading 2 levels deep, the structure looked like this:

Repo.get_by!(Menuitem, slug: slug, parent_id: 0)
    |> Repo.preload([{:children, from(m in Menuitem, order_by: m.order)}, children: [children: from(m in Menuitem, order_by: m.order)]])

The syntax you provided is incredibly useful as a point of comparison. Thanks again.

1 Like