Ash FrameworkAF
Ash Framework3y ago
27 replies
obsidian

Is it possible to pass a map to args instead of a list of attributes in code_interface?

I'd like to pull off something like:

actions do
  update :update_stats do
      argument :stats, :map

      Enum.map(arg(:stats), fn {key, value} ->
        change set_attribute(key, value)
      end)
    end
end


code_interface do

    define :update_stats, args: [:stats]

  end


but I get the following error:
Compilation error in file lib/leaderboard/data/resources/wallet.ex ==
** (Protocol.UndefinedError) protocol Enumerable not implemented for {:_arg, :stats} of type Tuple
    (elixir 1.14.4) lib/enum.ex:1: Enumerable.impl_for!/1
    (elixir 1.14.4) lib/enum.ex:166: Enumerable.reduce/3
    (elixir 1.14.4) lib/enum.ex:4307: Enum.map/2
    lib/leaderboard/data/resources/wallet.ex:21: (module)


Is there a way to dynamically pass in args that you want to update on the resource? Or do you have to hard code the set_attributes?

I'm trying to bypass the need to pass in each attribute in order every time. As their are many attributes and not all of them will be updated each time.
Was this page helpful?