Can't use `actor` on aggregates
Hi - I'm trying to use ^actor on aggregates but it's throwing an error.
This is my aggregate:
But calling:
Practice.load!(visit, :max_index, actor: user, authorize?: true)
causes:
Removing the ^actor
works as expected though (but doesn't filter what I need to ofc)21 Replies
Correct you can’t access the actor in aggregates. They are currently meant to be static.
You‘ll probably need to do it manually w/ a calculation
trying to do this as a custom calculation and I got this far:
But it's throwing a compile error:
visit_id
definitely exists on the AudioFile
resourcerequire Ash.Query
at the top of the fileah ok that makes sense. Ecto has a thing where it throws a warning that tells you to do that - might be helpful for Ash
There isn't actually a way for us to do that in this case unfortunately
well
I guess how does ecto do it
😆
I'm pretty sure its impossible...
incidentally I think there might be a bug in the docs:
https://ash-hq.org/docs/guides/ash/latest/topics/actions#idiomatic-actions
The top action takes an argument
user_id
let me check
i definitely saw it pop up recently
The
user_id
would only be there like that if the calculation takes an argument of user_id
You might want %{actor: %{id: user_id}}
ah ok got it
the docs bug is a little different though (unrelated to my code, just was looking at it while debugging this)...
In the docs, :top is defined as:
so it seems like this:
wouldn't work?
Ohh, I see what you mean
yeah, you're right 🙂
I'd suggest something like that (haven't tested it of course)
the idea of taking a list of visits is to allow you to compute the values in an optimized way
ah sort of dataloader pattern
makes sense
yeah, exactly
thanks!
my pleasure 🙂 If you don't mind, could you make an issue about the incorrect docs?
will do
I think this is the error I saw: https://github.com/elixir-ecto/ecto/blob/5644bfab248dc56fac078dfc231d7e5b9c3f5ad7/lib/ecto/query/builder.ex#L952
GitHub
ecto/lib/ecto/query/builder.ex at 5644bfab248dc56fac078dfc231d7e5b9...
A toolkit for data mapping and language integrated query. - ecto/lib/ecto/query/builder.ex at 5644bfab248dc56fac078dfc231d7e5b9c3f5ad7 · elixir-ecto/ecto
though I think it may have been a different one - I'll try to reproduce
Haven't looked at Ecto, but something like this should work:
Whether or not you'd want to in this case... :thinkies:
🤔 well, that only works if you do
use TheModule
right?
Ash.Query
doesn't have a __using__
macrouse Ash.Calculation
I don't think you should add this warning btw, surely Ash.Query
is not sufficiently universally used in Ash.Calculation
impls 😄yeah, agreed