Error while building reference
I'm trying to use the attributes of a relationship in a calculation but I get a runtime error. I attached my code and the error as a screenshot because Discord somehow prevents me from creating posts with more than 2000 characters.

9 Replies
I'm not sure, but maybe adding the load option will help https://ash-hq.org/docs/dsl/ash-resource#calculations-calculate-load
load: :vendor
otherwise I'd need to dig a little deeperI previously already unsuccessfully tried
load: [:vendor]
Now I added load: :vendor
, recompiled and tried it again but I still get the same error. I already had a look at the ash_postgres source code and it looks like vendor lacks a binding, but I'm not skilled enough to debug it there.
load: [:vendor]
would have been the correct syntax, my bad.
I have to take a closer look later, or maybe Zach swings by in the meantime and can just answer it πYou canβt reference related resources in a calculation
We should give it a better error
You can, however, refer to aggregates which reference related resources
Lemme move to my laptop to show you what it would oook like, once sec
Thank you very much for the help! Btw watched the Elixir Conf talk on YouTube and I'm absolutely hyped about the future of Ash π
That is the basic form of using an aggregate to get a single value from a related entity.
Honestly...I can make that not necessary, I just haven't done it yet π
I can make
calculate :name, expr(vendor.name <> " " <> model)
workMakes sense, it could potentially work for has_one, belongs_to relationships, but otherwise it's not clear which resource entity the name should come from
Exactly
we'd raise an error if any relationship had a
:many
cardinality
The other way is with an "inline aggregate"
Thank you very much! It works like a charm. I will probably keep the explicity aggregate because it might come handy later. Awesome π―
