Ash FrameworkAF
Ash Framework3y ago
86 replies
\ ឵឵឵

Proxying actions to other actions

I've found it a useful pattern to do some transformations that then proxy the remainder of the work to another action—often the primary action of its type.

The way I'm doing that is roughly:
actions do
  create :upstream do
    change fn cs, ctx ->
      # do some upstream stuff
      Session
      |> Changeset.new
      |> Changeset.for_action(:create, %{param: value}, Map.to_list ctx)
    end
  end
end


I've started getting a lot of the following:
warning: Changeset has already been validated for action :upstream.

In the future, this will become an error.

For safety, we prevent any changes after that point because they will bypass validations or other action logic.. To proceed anyway,
you can use `set_argument/3`. However, you should prefer a pattern like the below, which makes
any custom changes *before* calling the action.

  Resource
  |> Ash.Changeset.new()
  |> Ash.Changeset.set_argument(...)
  |> Ash.Changeset.for_create(...)


Is there a preferred way to execute this pattern? It does seem like I'm doing something quite like what the message recommends.
Was this page helpful?