Ash FrameworkAF
Ash Framework7mo ago
10 replies
EAJ

Accept subset of Ash.Type.Enum in action

I have an Ash.Type.Enum defined as
defmodule Dreng.Accounts.Role do
  use Ash.Type.Enum, values: [:superadmin, :admin, :farmer, :farmhand]
end

And the User resource is using it with
    attribute :role, Dreng.Accounts.Role do
      allow_nil? false
    end

In my create action I'd like to accept a role argument, but only :farmer or :farmhand should be allowed, and ideally I'd like to keep all the benefits of using Ash.Type.Enum like automatic casting. What would be the idiomatic way of accomplishing this?
Was this page helpful?