tellesleandro
Ecto allows to compose a query, like this:
def for_patio(query \\ __MODULE__, %Patio{} = patio) do
query
|> join(:inner, [pe], _ in assoc(pe, :patios), as: :patios)
|> where([patios: p], p.id == ^patio.id)
end
def for_parceiro(query \\ __MODULE__, %Parceiro{} = parceiro, voucher) do
query
|> join(:inner, [pe], ape in assoc(pe, :parceiros_precos_estadias),
as: :parceiros_precos_estadias
)
|> where(
[parceiros_precos_estadias: ape],
ape.parceiro_id == ^parceiro.id and
ape.voucher == ^voucher
)
end
I can query the resource in different ways:
- Resource.for_patio(patio) |> Repo.all
- Resource.for_parceiro(parceiro, voucher) |> Repo.all
- Resource.for_patio(patio) |> Resource.for_parceiro(parceiro, voucher) |> Repo.all
How do I do that using Ash?
Trending in Questions
Hi all,
I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
I’m very new to Elixir, so sorry if this is a silly question:
I am wondering what happens to the mailbox of a process when the machine i...
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
New
Background
When trying to execute mix release on a Windows 11 machine for a Phoenix project I get the following error:
* assembling mark...
New
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New
When I use Mix.install with a git dependency, using git@github.com:... how do I change the SSH identity used?
I’ve got two Github accoun...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
Hi everyone :waving_hand:
I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
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
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #elixirconf-us
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #elixirconf-eu
- #processes
- #security
- #api
- #forms
- #performance










Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
zachdaniel
You’d use calculations for this:
And then you can query like
You cold then call a code interface and provide this query
Or use the underlying api for it
zachdaniel
You can also just let the caller filter
this is safe to let them do, because all logic ultimately goes through a read action, and is always run through your policies for access rules.
tellesleandro
Thanks @zachdaniel. With all this explanation I can move on. I think I get stucked 'cause I feel I have to put all queries inside actions. As far as I can see, it’s not true. Many examples you give show queries that don’t rely on actions, right? In this case, should I create a regular module and put there the queries inside regular functions?
zachdaniel
Honestly it just depends on how you’re using it. For instance, if you’ve got a live view somewhere, you can do this:
But you can also do
If you are considering making a module somewhere with functions like:
Then at that point I would suggest making it an action, i.e
If you need caller-level composition, then calculations are a good choice.
I know it would be nice if there was “one right answer” but in these case it often comes down to what kind of interface you would need. The general rule of thumb though is: when in doubt, put stuff in an action that does specifically what you need.
tellesleandro
Great. I’ll follow these advices. Thanks.
zachdaniel
No problem
I appreciate your questions, and I while we definitely want to improve the documentation, having these kinds of questions here in the forum will help other people when they have similar questions. Documentation improvements are a longer term type thing, but this will help people in the short term 
tellesleandro
Sure. I hope more devs jump into Ash’s world and take advantage of it. These newbie’ questions may help them too.
yasoob
Hey @tellesleandro i just wanna say that your questions and the ensuing discussion is very helpful for newbies like me. Thanks for asking these questions!
tellesleandro
Welcome @yasoob. I’m developing real world application for real world customers, not only CRUD examples. So, expect to find more and more newbie questions from me here.