Sorting on the first relationship in an aggregate

I want to do an aggregate over a m2m table where the order is important, so I write the code below but whatever I do I can't seem to sort on the first table. Should I be able to do that?

  aggregates do
    list :phone_numbers_list, [:some_many_to_one_table, :user], :phone_number do
      public? true
      sort expr(some_many_to_many_table.order)
    end
  end
Solution
tldr: Calculations ❤️

The solution was to use a calculation on :some_many_to_one_table that got the phone number:

  calculations do
    calculate :phone_number, :string, expr(some_many_to_one_table.phone_number), public?: true
  end


And then create another calculation on the first resource:

    calculate :phone_numbers_list,
              {:array, :string},
              expr(list(some_many_to_one_table, query: [sort: :order], field: :phone_number))


And then I could load everything and produce a super pretty query with the best type annotation.

Ash.load!(clock, :phone_numbers_list, actor: context.actor) |> IO.inspect()


$1::text[])::text[]::text[]
Was this page helpful?