How to sort by a value from a joined resource?

Let’s say I have this resource;

defmodule A do
  ...
  relationships do
    belongs_to :b, B do
      allow_nil? false
      attribute_writable? true
    end
  end
end

defmodule B do
  ...
  attributes do
    ...
    attribute :score, :decimal
  end
end

I want to query the resource A but join resource B and sort it by the score attribute. How can I do that?

The most straightforward way is to use a calculation and sort on the calculation.

calculate :score, :decimal, expr(b.score)

and now you can sort by score :slight_smile: