Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance set_attribute to enable attribute copying #1507

Open
jechol opened this issue Oct 8, 2024 · 1 comment
Open

Enhance set_attribute to enable attribute copying #1507

jechol opened this issue Oct 8, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@jechol
Copy link
Contributor

jechol commented Oct 8, 2024

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 jechol added enhancement New feature or request needs review labels Oct 8, 2024
@zachdaniel
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Someday
Development

No branches or pull requests

2 participants