adopted-ember-addons / adopted-ember-addons/ember-changeset
Relationships and Changesets
- Dominant language
- JavaScript
- Stars
- 425
- Forks
- 136
- PR merge metrics
- No merged PRs in 30d
Description
When working with changesets, this pattern is quite common:
```js
let home = new Address();
let work = new Address();
let user = new User();
user.addresses = [home, work];
let validator = function() {};
let model = Changeset(user, validator);
```
```hbs
Personal details
{{input type='text' value=model.firstName}}
Addresses
{{#each model.addresses as |address|}}
{{input type='text' value=address.street}}
{{input type='text' value=address.city}}
{{/each}}
```
What I'd like to do here is to make changes to the address instances and buffer them inside a changeset. So that I can do rollback on the model and automatically have rollbacks applied to all child changesets too.
Maybe by specifying which relationships should create proxy changesets and buffer, e.g. `let model = Changeset(user, validator, { nested: ['addresses'] });` or similar (opt-in).
Right now changesets seems to support access via keys, e.g. `changeset.set('profile.url', '…')` but not `changeset.get('profile').set('url', '…')`
1. Has there been any discussion on supporting relationships, such that the handlebars example above would work with rollback/save on the user, with changes applied to nested addresses?
2. Would also be good to support rollback/apply for changes to the collection itself, i.e. adding/removing addresses. Maybe via an API such as `model.get('addresses').add(vacationHome);` where `model.get('addresses')` would return an instance of e.g. `ChangeSetList`.
Related issues:
- https://github.com/poteto/ember-changeset/issues/549
- https://github.com/poteto/ember-changeset/issues/543
Contributor guide
Assessment
This issue has not been assessed yet.