Adding a custom sort
I have a field which is an atom. I want to sort it with a custom sort order:
I am imagining something like this but I can;t find the exact syntax:
prepare fn query, _ ->
query
|> Ash.Query.sort([
Ash.Sort.expr_sort(
case :deliver_before do
:"10am" -> 1
:"2pm" -> 2
:"6pm" -> 3
:"10pm" -> 4
:no_preference -> 5
end,
:integer
)
])
end
is this possible in ash?
2 Replies
You can do it, you just need to use a
cond
statement
since we can't do case statements in expressions
I would also suggest to make this a calculation
Then you can Ash.Query.sort(query, :deliver_before_sort)
great thank you.