Access calculation from relation caluclation.
I got a resource A the defines
And I got resource B that want to expose the same field through the association
Looks like I cannot do this, should I just define the original calculation in B instead?
18 Replies
The reason I need to expose the same attribute is to being able to sort B by that specific field
You can do it but only if they are all expression calculations
no that source calcualtion is a module
It can still be an expression calculation
Just has to define
expression/2
ok so has to be exclusively at the database level
Yep
Thanks
i'm not sure if a bug but setting the share context in the parent resource
this context is available in
def calculate(records, _opts, context) do
but not in def expression(opts, context) do
in the
source_context
key?
May be a bug yesone more thing I thought that implementing
def expression(_opts, context) do
would automatically run it but is still asking to implement calculate
I can take care of that bugYou shouldn't have to implement
calculate
fwiw this is loaded from. graphql query
🤔
question
what if you do
mix compile --force
?
Can I see the calculation?do you have
use Ash.Resource.Calculation
in your module?yes
mix compile --force didn't help
i'm trying to change the implementation
ok
expr(count(user.access_logs))
works just fine
so is an error with the expression not being raised?🤔 I'm not sure, I've never seen it complain about that
having
expression/2
should be all you needso removing the cond block allows to raise this error
was the block not allowing the compilation of
expression/2
, (?)
ok so I was able to resolve it remove the date builtins functions, so I assume for some reason the cond do
was preventing the error to pop outstrange
Can you open an error w/ a stacktrace where it was trying to access
\.calculate
?