Ash FrameworkAF
Ash Framework3y ago
2 replies
Alan Heywood

Metaprogramming with expressions

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
Was this page helpful?