action argument default to another argument?

Trying to use the value passed in one argument as a default value for a second argument. Is there a way? Something like:
create :new_record do
primary? true
argument :short_name, :string, allow_nil?: false
argument :long_name, :string, default: arg(:short_name)
change set_attribute(:short_name, arg(:short_name))
change set_attribute(:long_name, arg(:long_name))
end
create :new_record do
primary? true
argument :short_name, :string, allow_nil?: false
argument :long_name, :string, default: arg(:short_name)
change set_attribute(:short_name, arg(:short_name))
change set_attribute(:long_name, arg(:long_name))
end
I've tried a few variations on the above and keep getting InvalidArgument compilation errors from Ash.
1 Reply
ZachDaniel
ZachDaniel2y ago
There is no built in way to do that you'll need to use a custom change
change fn changeset, _ ->
case Ash.Changeset.fetch_argument(changeset, :long_name) do
{:ok, _} -> changeset
:error -> Ash.Changeset.set_argument(changeset, :long_name, Ash.Changeset.get_argument(changeset, :first_name))
end
end
change fn changeset, _ ->
case Ash.Changeset.fetch_argument(changeset, :long_name) do
{:ok, _} -> changeset
:error -> Ash.Changeset.set_argument(changeset, :long_name, Ash.Changeset.get_argument(changeset, :first_name))
end
end
that kind of thing

Did you find this page helpful?