nallwhy
I’m trying to sum only the copies_sold of :studio albums using an aggregate, but I’m not sure how to apply a filter to the joined records.
Here’s a simplified version of my resource:
def AshPg.Music.Artist do
...
aggregates do
sum :studio_copies_sold, [:albums], :copies_sold do
# Invalid reference albums.type
# filter expr(albums.type == :studio)
# Not working
join_filter [:albums], expr(type == :studio)
end
end
end
And here’s a test that creates an artist with multiple albums, where only one is of type :studio. The aggregate should return 1_000_000, but currently it’s returning the total sum of all album types.
defmodule AshPg.Music.ArtistTest do
...
test "solo_copies_sold" do
artist =
Music.create_artist!(%{
name: "250",
albums: [
%{title: "Rear Window", type: :single, copies_sold: 1000},
%{title: "Bang Bus", type: :single, copies_sold: 2000},
%{title: "뽕", type: :studio, copies_sold: 1_000_000}
]
})
%{studio_copies_sold: studio_copies_sold} = artist |> Ash.load!([:studio_copies_sold])
# The sum of copies sold for studio albums should be 1_000_000
assert studio_copies_sold == 1_000_000
end
end
join_filter doesn’t seem to have any effect.
https://github.com/nallwhy/ash_pg/commit/4a84d244554620cb4ff602e9dcaa12bcaccf591d
Is there a correct way to apply a filter to aggregates based on joined relationships? Any help would be appreciated.
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 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
zachdaniel
join_filteris for “intermediate” relationships, not the destination relationship.nallwhy
Thanks — I completely misunderstood the code below.
https://github.com/ash-project/ash/blob/acd2e31d4ecc1602bc3c259db383d202ce90ad25/documentation/topics/resources/aggregates.md#L96-L109
filter expr(redeems.redeemed == true): I thought it was accessing resource →redeems.redeemed, but it’s actually going throughdeal→redeems.redeemed.join_filter [:redeems, :deal], expr(active == parent(require_active)): thejoin_filteris used to accessparent, which makes sense.