Another calculations query

I have 'Job' which is related to a 'Service' via another resource (not defined as a :through). I need a calculation that does something like
expr(status == ^JobStatus.completed() and order_service.service.track_weights == true and is_nil(weights)
expr(status == ^JobStatus.completed() and order_service.service.track_weights == true and is_nil(weights)
I've already defined the first aggregates, but now I'm getting an error telling me that I need to provide field type for first, so I'm assuming that something along my chain of first aggregates is not working? or am I not allowed to define an aggregate of an aggregate?
17 Replies
kernel
kernelOP3y ago
side note, are there any plans to add :through support to has_one?
ZachDaniel
ZachDaniel3y ago
not "plans" specifically, but would be great 😄
kernel
kernelOP3y ago
I'm assuming it's not working because I have an aggregate of an aggregate
ZachDaniel
ZachDaniel3y ago
Yep Aggregates over aggregates aren't supported currently Can you lift up the aggregate? like adding first :thing, [:foo, :bar, :baz], ...
kernel
kernelOP3y ago
will that automatically load things in the path?
ZachDaniel
ZachDaniel3y ago
What do you mean load things in the path? it will happen in the query aggregates support a single relationship or relationship path
kernel
kernelOP3y ago
first :track_weight, [:order_service, :service], :track_weights_on_pickup_and_empty ??
ZachDaniel
ZachDaniel3y ago
yeah, exactly
kernel
kernelOP3y ago
order_service is a resource, as is service
ZachDaniel
ZachDaniel3y ago
assuming those are the relationship names
kernel
kernelOP3y ago
didn't know that was supported 🙂
ZachDaniel
ZachDaniel3y ago
we also recently optimized first when used across exclusively belongs_to relationship paths where it will just do a simple join and select, not the normal aggregate logic
kernel
kernelOP3y ago
was this the stuff in main liners?
ZachDaniel
ZachDaniel3y ago
You can do the same thing for all of the aggregates, can be really useful sometimes. Yep! Although relationship paths in aggregates has been supported since the beginning
kernel
kernelOP3y ago
TIL 🙂 let's say you have a boolean, can you just reference it in an expression like expr(status == :foo and track_weights?) assuming it's defined as track_weights?
ZachDaniel
ZachDaniel3y ago
yeah, should be able to 👍
kernel
kernelOP3y ago
thankyou 🙏🏿

Did you find this page helpful?