In an action, how can I sort on a field in a relation?

I have an action performing a read operation with a specific relation loaded. That relation contains a position field that I wish to sort on first, then the primary id create_ts.
prepare build(load: [:status], sort: [:status.position, :create_ts])
prepare build(load: [:status], sort: [:status.position, :create_ts])
That obviously doesn't work, but it is what I wish to accomplish.
1 Reply
ZachDaniel
ZachDaniel3y ago
The current way is by adding an aggregate
aggregates do
first :status_position, :status, :position
end
aggregates do
first :status_position, :status, :position
end
And then you can sort on sort: [:status_position, :create_ts] We will likely add support for using to_one and has_one style relationships directly in sort

Did you find this page helpful?