Skip to content

Instantly share code, notes, and snippets.

@mrdotb
Created November 28, 2023 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrdotb/7dfa85edb84dd3512f6cff938593ef2e to your computer and use it in GitHub Desktop.
Save mrdotb/7dfa85edb84dd3512f6cff938593ef2e to your computer and use it in GitHub Desktop.
Ash runtime error on action argument array of self type

Ash runtime error on action argument array of self type

Application.put_env(:ash, :validate_api_resource_inclusion?, false)
Application.put_env(:ash, :validate_api_config_inclusion?, false)
Mix.install([:ash], consolidate_protocols: false)

Working arguments array of dummy

defmodule Working.Dummy do
  use Ash.Resource

  attributes do
    uuid_primary_key(:id)
    attribute(:name, :string)
  end
end

defmodule Working.User do
  use Ash.Resource

  actions do
    defaults([])

    create :create_with_dummies do
      accept([])

      argument :dummies, {:array, Working.Dummy} do
        allow_nil?(false)
      end

      change(fn changeset, _ ->
        dummies = Ash.Changeset.get_argument(changeset, :dummies)
        # do something with dummies
        changeset
      end)
    end
  end

  attributes do
    uuid_primary_key(:id)
    attribute(:name, :string)
  end
end

Breaking arguments array of self

defmodule User do
  use Ash.Resource

  actions do
    defaults([])

    create :create_with_friends do
      accept([])

      argument :user_friends, {:array, User} do
        allow_nil?(false)
      end

      change(fn changeset, _, _ ->
        user_friends = Ash.Changeset.get_argument(changeset, :user_friends)
        # do something with user_friends
        changeset
      end)
    end
  end

  attributes do
    uuid_primary_key(:id)
    attribute(:name, :string)
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment