ash-project / ash-project/ash

Enhance set_attribute to enable attribute copying

Open
#1,507 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Elixir
Stars
2.5k
Forks
422
Avg merge
23h 26m
Merged PRs (30d)
46

Description

**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)```

Contributor guide

Open the contributing guide

Research direction

Start with the Ash.Changeset.change_attribute and Ash.Changeset.get_attribute calls in the issue, then trace the set_attribute change entry point used in the resource action DSL. Check the relevant change tests and verify that the proposed from: syntax copies the source attribute value to the destination attribute.

Written by the indexing model from the issue text.

Assessment

Tech stack
elixir
Domain
backend-api-design
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.