Using struct data in filter expressions
I think I've tried to do this a few times and have never gotten it to work properly.
I have a calculation that takes a struct as an argument, and I want to use data from that struct in the expression, eg.
This doesn't error, but generates SQL like
ash_elixir_or((d0."speaker_faction_id"::text IS NULL)::boolean, (d0."speaker_faction_id"::text::text = NULL::text)::boolean)::boolean)::boolean)
(so the second part isn't working properly).
It's probably something simple but I've tried lots of things like ^arg(:npc)[:id]
, ^ref([arg(:npc)], :id)
, and nothing else will even compileSolution:Jump to solution
instead of
^get_path(arg(:npc), :faction_id)
it should be get_path(^arg(:npc), :faction_id)
8 Replies
found this thread https://elixirforum.com/t/read-action-by-related-struct/61955/5?u=sevenseacat but
expr(topic_id == ^arg(:topic) && (is_nil(speaker_faction_id) ||
speaker_faction_id == (^arg(:npc))[:faction_id]))
doesn't work either - gives an error:
with the calculation being used in an action like:
We should make it simpler. But IIRC
(^arg(:arg))[:foo]
should work
But if not we can make it work and/or fix the get_path version for example
Maybe you could reproduce in a test in ash core?so its supposed to work? right. more investigation
and/or a failing test
There is supposed to at least be some way to do it yes
ahhhh I had the pin in the wrong place
But
^arg(:foo)[:path]
doesn't work because of how pin operators workSolution
instead of
^get_path(arg(:npc), :faction_id)
it should be get_path(^arg(:npc), :faction_id)
(was looking through the tests for
get_path
in ash core)