sezaru
After Ash update, calculation with to_many relatioonship stopped working
In my resource, I have the following many_to_many relationship:
many_to_many :favorited_by_users, User do
through FavoriteProperty
join_relationship :property_favorites
source_attribute_on_join_resource :property_id
destination_attribute_on_join_resource :user_id
end
I want to have a calculation that will tell if a user favorited that resource:
calculate :favorite?,
:boolean,
expr(exists(property_favorites, user_id == ^actor(:id)))
This used to work fine, but now after updating to 2.15.19, now I guet this error:
** (Ash.Error.Unknown) Unknown Error
Context: resolving query on fetch Marketplace.Markets.Property.list_user_favorites
* Context: resolving query on fetch Marketplace.Markets.Property.list_user_favorites
** (RuntimeError) Only to-one relationship references are allowed in a calculation reference paths. Got: "property_favorites" in favorite?(%{tracer: nil, actor: #Marketplace.Accounts.User<full_name: #Ash.NotLoaded<:calculation>, organization_roles_as_string: #Ash.NotLoaded<:calculation>, referred_by: #Ash.NotLoaded<:relationship>, created_by: #Ash.NotLoaded<:relationship>, impersonate_permissions: #Ash.NotLoaded<:relationship>, preference: #Ash.NotLoaded<:relationship>, organization: #Ash.NotLoaded<:relationship>, token: #Ash.NotLoaded<:relationship>, __meta__: #Ecto.Schema.Metadata<:loaded, "users">, id: "e1812726-25fe-43df-97d7-68107787b8b0", email: #Ash.CiString<"abe2045@willms.org">, phone_number: "+1 (555) 555-5555", first_name: "Torey", surname: "Torphy", roles: [:super_admin], organization_roles: [:agent], confirmed_at: ~U[2023-10-19 14:49:08.752152Z], active?: true, referral_code: "a9f88a40-98f0-40c2-95b7-9fecbd94a83d", normalized_full_name: "torey torphy", inserted_at: ~U[2023-10-19 14:49:08.746216Z], updated_at: ~U[2023-10-19 14:49:08.753379Z], organization_id: "185e2073-baa8-48f7-ba7b-cc873104a528", created_by_id: nil, referred_by_id: nil, aggregates: %{}, calculations: %{}, ...>, authorize?: true, tenant: nil})
To extract a single value from a to_many relationship or path that includes a to_many relationship, use a `first` aggregate.
The error suggests to use an aggregation, but AFAIK I can’t access the actor in the aggregation.
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated!
To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead.
Sta...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New
Other Trending Topics
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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #performance










First 7 of 7 Posts
zachdaniel
This looks like an error. That validation is being overly zealous. Let me take a look.
zachdaniel
I’ve pushed a fix to
mainthat temporarily disables this validation. Please try it out when you get a chance to confirm that it resolves the issue for you.sezaru
That change fixed it!
But now I’m having other tests failing hahaha…
Did the Decimal type changed in some way in the newer versions? I expected to get Decimal types in my Ash.Changeset attributes fields when the field is
:decimal, but they are getting normal strings now.If this is some kind of bug just let me know and I will create a new topic to it
sezaru
Ah, ignore this, I was using plain strings to define the defaults in my decimal attributes, example:
This worked and would be converted into a decimal in older versions, but not in newer ones. I just changed the default to
Decimal.new("0.035")and it worked fine.zachdaniel
zachdaniel
Ah, okay yeah, I understand. I made some changes to defaults and I didn’t anticipate that. I will revert those changes
zachdaniel
Actually, I will fix it under the hood where we cast the value and store the casted value.