Ash FrameworkAF
Ash Framework4mo ago
10 replies
Rise

Changing attributes in action

I am trying to simplify the commented out code by using expr() , but i get an InvalidAttributeError with the hint string_downcase(nil)

    create :create do
      accept [:name]
      
      # what i want, but does not work
      change set_attribute(:name, expr(string_downcase(^arg(:name))))
      
      # what works
      change fn changeset, _ ->
        new_name =
          Ash.Changeset.get_argument_or_attribute(changeset, :name)
          |> String.downcase()

        Ash.Changeset.update_change(changeset, :name, new_name)
      end
    end


Also I am not sure if to put it in before_action or not since from what I saw the change does not appear in the Phoenix form. So in both cases it should only appear in the database ?
Solution
You can't use expressions in that context
Was this page helpful?