Sakthibalan
Fetch unique users with distinct query
How to fetch unique user by ‘user_id’ a query with distinct
Resources:
-
Ash.Domain.User
-
Ash.Domain.Project
has_many :milestones -
Ash.Domain.Milestone
belongs_to :project
has_many :tasks -
Ash.Domain.Task
belongs_to :milestone
has_one :task_assignee -
Ash.Domain.TaskAssignee
belongs_to :user
belongs_to :task
How to fetch unique users from a project using a distinct query?
I tried this below query:
Project
|> Ash.Query.filter(name: “example”)
|> Ash.Query.load([milestones: [tasks: :task_assignee]])
|> Ash.Query.distinct([:user_id])
|> Ash.read!()
- unknown error: :distinct
Most Liked
zachdaniel
Creator of Ash
I think you’d have a lot better luck with something like:
User
|> Ash.Query.filter(exists(task_assignee.task.milestone.project, name == "example"))
than trying to load distinct users starting at Project. If you did want to do it, though, you’d need something like:
Project
|> Ash.Query.filter(name: “example”)
|> Ash.Query.load([milestones: [tasks: task_assignee: Ash.Query.distinct(TaskAssignee, :user_id)]])
|> Ash.Query.distinct([:user_id])
|> Ash.read!()
|> # extract all of the task assignees from this data structure, because you will get back a list of `%Project{}`
1
Popular in Questions
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
If I have a post route which an argument:
post /my_post_route/:my_param1, MyController.my_post_handler
How would get the post params ...
New
Hi All,
I set a environment variables in dev.exs , like below code.
when i start server, how can i set the ${enable} value?
thanks.
d...
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
Other popular topics
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
New
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something…
Haskell reminds me of Java, and e...
New
Hello!
tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability.
After spen...
New
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New
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
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









