ash
ash copied to clipboard
Enhance set_attribute to enable attribute copying
Is your feature request related to a problem? Please describe. There's no simple way to copy a value from one attribute to another within the same resource. Current approach is verbose:
change fn changeset, _context ->
Ash.Changeset.change_attribute(changeset, :bar, Ash.Changeset.get_attribute(changeset, :foo))
end
Describe the solution you'd like
resource do
actions do
create :create do
accept [:foo]
change set_attribute(:bar, from: :foo)
end
end
end
Describe alternatives you've considered Introduce a copy_attribute function for a more declarative syntax:
copy_attribute(:bar, from: :foo)
I'd suggest a built in change called copy_attribute instead of adding more cases to set_attribute/2.