How do you sort by substring?

Current in my resource
actions do
defaults [:read]

read :list do
prepare build(sort: [sale_reference: :desc])
filter expr(is_nil(project))
end
end
actions do
defaults [:read]

read :list do
prepare build(sort: [sale_reference: :desc])
filter expr(is_nil(project))
end
end
I would like to sort by substring -> select * from resources order by substring(sale_reference from 3) desc
2 Replies
ZachDaniel
ZachDaniel2y ago
You can add a calculation to the resource for example:
calculate :name, :string, expr(fragment(“substring(?, ?)”, sale_reference, 3))
calculate :name, :string, expr(fragment(“substring(?, ?)”, sale_reference, 3))
And then you can sort by that
Terry Lee
Terry LeeOP2y ago
Again, my Ash arsenal expands! Thank you! PS. I wanted to say, my first Ash-driven LiveView app went live last week. -> theweighin.sejutakg.my

Did you find this page helpful?