sezaru
I have an Ash query that I need to convert into an Ecto query to do some more complex manipulations (group by, etc) using the Ash.Query.data_layer_query/2 function.
Is there any way for me to either transform my Ecto query back into an Ash.Query struct so I can use its pagination support or use Ash pagination support directly in my ecto query results?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
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
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
zachdaniel
I don’t believe there is a way to do that, no. What you can potentially do is use the
modify_queryoption of read actions and do your grouping there. It depends a lot on what you’re doing though.sezaru
The problem is that the query will group based on the joined resource and return it plus some aggregations.
Here is the query:
So, I have an action from the
Transactionresource that returns the following ash query (showing in sql):From that, I’m transforming it into an ecto query and doing the
group_bypart andselectpart.If I use the read action, if implemented from the
Transactionresource, it would expect to return transactions, but it actually returns entities which is another resource.If I implement it in the
Entityresource, then myfrompart of the query will use theentitiestable instead of thetransactionsone.Also, the reason that I’m not doing that query directly from the Entity resource and using aggregations, is because all my filters (the where part, which I removed a lot of lines) are all handled by my form and filter it based in transactions columns.
zachdaniel
Hm…it might be possible to rewrite your query to be based on entities, and make it an action on entities, which would simplify this significantly.
Like, you’ve got
count(t0.*) purchaseswhich appears to be “the number of transactions for a given entity that was between x and y date”.You could do that as a calculation on entities like so:
Specifying each calculation this way is pretty verbose, for sure but you’d have a flexible solution that would then support loading it directly, i.e
zachdaniel
Otherwise you’re probably stuck implementing your own custom logic outside of Ash.
drikanius
Hi Zach.
I tried something like this:
Considering that buy_date is a Transaction attribute, should I be able to access it in this query?
Using the suggested calculate I got this error:
As a reference I created an aggregate to list buy dates like
list :transaction_dates, :transactions, :buy_dateand this part works to access buy_date
drikanius
Sorry, my bad
filter: [ :buy_date < arg(:start_date) and :buy_date > arg(:end_date)]this way its compile
zachdaniel
The filter must be wrapped in its own
expr. Using atoms isn’t what you want.drikanius
Yeah. I realized when it returned zero =P
drikanius
Is there any way to use
suminstead ofcountin expr?zachdaniel
Yes, you will just need to add the
fieldoption,sum(foo.bar, field: :field)