Metaprogramming with expressions
I am generating a module at compile time, and my
Ash.Query.filterAsh.Query.filter doesn't work as intended. Please see comment belowdefp 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__)
)
enddefp 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