l00ker
l00ker
AEAsh Elixir
Created by l00ker on 2/17/2023 in #support
Pagination 'count' is not accurate if the SQL query result contains duplicate id's
The pagination count SQL query is using DISTINCT like this:
SELECT coalesce(count(DISTINCT t0."id"::bigint), $1::bigint)::bigint FROM (...) ...
SELECT coalesce(count(DISTINCT t0."id"::bigint), $1::bigint)::bigint FROM (...) ...
If the result set returned by the sub query has duplicate ids then the count doesn't reflect the actual number of rows returned by the sub query because DISTINCT is removing them from the count. Is there any way to remove DISTINCT from the pagination count query?
107 replies
AEAsh Elixir
Created by l00ker on 2/2/2023 in #support
Calculate only on a read action
Hello everyone. Just starting out with Ash and so far, so good. I'm starting to figure a few things out. What I'm currently struggling with is having a calculate only run on a read action. I have an embedded resource where I'm using a calculate to generate a URL from another field. Here is a snippet from parent resource where the embedded is loaded:
attributes do
...
attribute :myembed, MyEmbed do
constraints [load: [:url]]
allow_nil? false
end
...
end
attributes do
...
attribute :myembed, MyEmbed do
constraints [load: [:url]]
allow_nil? false
end
...
end
That works and I get the calculated :url field injected into the embedded resource when reading items. Yay! My issue is that the :url field is also being written to the embedded field on create. How can I have the calculate run only during the read actions? I tried using a various Ash.Query functions in aprepare in the read action of the embedded resource as well as in the read action of the parent, but couldn't get it load and/or not generate errors.
31 replies