moxley
I’m trying to query members that have all the given tag IDs. The code needs to dynamically build an expression like:
member.member_tags.tag_id = tag_id1
AND member.member_tags.tag_id = tag_id2
AND member.member_tags.tag_id = tag_id3
where tag_id1, tag_id2, and tag_id3 come in as a list.
I tried this:
Enum.reduce(tag_ids, query, fn id, query ->
Ash.Query.filter(query, exists(member_tags.tag_id == ^id))
end)
That results in:
[warning] `1b6d55b5-7d6a-478d-9872-86153c141ff0`: AshGraphql.Error not implemented for error:
** (Ash.Error.Query.NoSuchFunction) No such function exists for resource GF.Members.Member2
(elixir 1.16.1) lib/process.ex:860: Process.info/2
(ash 3.1.3) lib/ash/error/query/no_such_function.ex:5: Ash.Error.Query.NoSuchFunction.exception/1
(ash 3.1.3) lib/ash/filter/filter.ex:3311: Ash.Filter.resolve_call/2
(ash 3.1.3) lib/ash/filter/filter.ex:2513: Ash.Filter.add_expression_part/3
(ash 3.1.3) lib/ash/filter/filter.ex:2451: anonymous fn/3 in Ash.Filter.parse_expression/2
I tried playing with Ash.Expr.expr():
expression = Ash.Expr.expr(true)
Enum.reduce(tag_ids, expression, fn id, expression ->
Ash.Expr.expr(^expression and member_tags.tag_id == ^id)
end)
query = Ash.Query.filter(query, ^expression)
But the filter part of the query always came back as true.
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex











Showing Posts 1 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
sevenseacat
I think your first attempt was closer to the mark, but the syntax isn’t quite right.
The docs are a bit sparse, but looking at Aggregates — ash v3.29.3, I think something like
exists(member_tags, query: [filter: tag_id == ^id])might work?zachdaniel
Exists is a special case because it was a calculation before the exist aggregate was a thing.
Example here: Expressions — ash v3.29.3
moxley
I tried:
Which produced:
I tried:
It produced:
The documentation that @zachdaniel pointed to doesn’t cover the case where the record’s has_many relationship needs to match every value in a list.
Is there a solution for this?
zachdaniel
The
query: [filter: ....]variation won’t work. That is the syntax for inline aggregates, whereasexistsis special. The snippet I posed should work.The kind of query you are writing is, in general, not a very easy query to write. There are a few ways you could do it. Your first example was very close to correct
Using exists
Would do what you want. This will result in a rather large SQL query w/ an
EXISTSper tag_id you’re searching for (and would probably be fine in general).Using
count/2However, you could also do something like this which would result in joining once. Only works if your join resource is unique on
member_idandtag_id.And here you can see the syntax @sevenseacat was getting at in her first response. That syntax just happens to not apply to
exists/2You may want to profile/try each out to see how it performs in your use case.
moxley
They both worked!
I had to modify the second one, to add the
queryfirst argumentIndeed, the join table should be unique on Member and Tag, so this solution is probably better.