Ash FrameworkAF
Ash Framework7mo ago
3 replies
cr0nk

Enforce each item is unique in attribute array

Hi, is there a way to set a constraint on this array attribute, that enforces each item to be unique?

For example it should not allow [:en, :en] .

attribute :languages, {:array, :atom} do
    default [:en]
    constraints [
      min_length: 1,
      items: [
        one_of: [:en, :de, :fr],
      ]
    ]
  end


Thanks in advance!
Was this page helpful?