dongwooklee96
I want the date to be the key and I want to return the resources in an array, should I use an action to make this possible in Ash?
Hello,
...
attributes do
uuid_primary_key :id
attribute :title, :string do
allow_nil? false
end
attribute :date_of_record, :date do
allow_nil? false
end
attribute :date_of_visited, :date
attribute :pain_of_scale, :integer, constraints: [min: 1, max: 5]
attribute :memo, :string
attribute :doctor_opinion, :string
create_timestamp :created_at do
private? false
end
...
I have the above resources defined and I want to group by date_of_visited and get back an array of resources with date as key value. How can I do this?
Additionally, we’d like to see pagination applied as well.
expected:
{
"2024-01-02": [{resource}, {resource}, ....],
"2024-03-02": [{resource}, {resource}, ...]
}
Marked As Solved
zachdaniel
Yes, sorry about that
I was at ElixirConf EU, so didn’t have as much time to expand on my forum post answers.
Given this type:
defmodule Dentallog.Types.GroupByDateDiary do
use Ash.Type.NewType,
subtype_of: :map
use AshGraphql.Type
@impl AshGraphql.Type
def graphql_type(_), do: :group_by_date_diary
end
you could then use it in your action
action :group_by_date_of_visited, Dentallog.Types.GroupByDateDiary do
run fn input, _context ->
{:ok, group_by_date_of_visited()}
end
end
Also Liked
chef
You’ll probably want to combine a generic action with an optional paginated read action. You can pass in your pagination parameters into the read action and then transform those results into the desired format.
zachdaniel
You can use Ash.Type.NewType to create a new type of map, and then you can use def graphql_type(_), do: :your_type
dongwooklee96
It works! ![]()
You’re right, I did think you’d be busy with ElixirConf EU 2024.
Thanks as always for your hard work.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance










