defmodule MyResource do
use Ash.Resource, data_layer: AshPostgres.DataLayer
actions do
read :custom_sort do
argument :sort, :atom do
constraints [one_of: [:newest, :oldest]]
allow_nil? false
end
build(sort: [inserted_at: expr(^arg(:sort) == :newest do :asc else :desc end)])
end
end
end
defmodule MyResource do
use Ash.Resource, data_layer: AshPostgres.DataLayer
actions do
read :custom_sort do
argument :sort, :atom do
constraints [one_of: [:newest, :oldest]]
allow_nil? false
end
build(sort: [inserted_at: expr(^arg(:sort) == :newest do :asc else :desc end)])
end
end
end