ash icon indicating copy to clipboard operation
ash copied to clipboard

Enhance set_attribute to enable attribute copying

Open jechol opened this issue 1 year ago • 1 comments

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)

jechol avatar Oct 08 '24 03:10 jechol

I'd suggest a built in change called copy_attribute instead of adding more cases to set_attribute/2.

zachdaniel avatar Oct 08 '24 11:10 zachdaniel