Metaprogramming with expressions
_ahey:
I am generating a module at compile time, and my
Ash.Query.filter
doesn’t work as intended. Please see comment below
defp generate_oban_worker_module(module, cache) do
contents =
quote do
require Ash.Query
use Oban.Worker, ...
@impl Oban.Worker
def perform(%Oban.Job{args: %{"id" => id}}) do
record =
unquote(cache.module)
# The following line doesn't work.
# It is evaluating to true and returning all records
|> Ash.Query.filter(id == ^id)
|> unquote(cache.api).read_one!(authorize?: false)
...
end
Module.create(
worker_name(module, cache),
contents,
Macro.Env.location(__ENV__)
)
end
_ahey:
Found it 😀 – I had to use
ref
like this:
Ash.Query.filter(ref(:id) == ^id)
zachdaniel:
yep!