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

Different forms of 'get' return different results for ember-data models #594

Closed
flynnawtc opened this issue May 17, 2021 · 1 comment · Fixed by #596
Closed

Different forms of 'get' return different results for ember-data models #594

flynnawtc opened this issue May 17, 2021 · 1 comment · Fixed by #596

Comments

@flynnawtc
Copy link

Version

main

Test Case

Thank you @snewcomer for the prompt response and fix to #592
I have been testing it since you updated validated-changeset earlier, and it does resolve the problem in most cases, but when I am working with ember-data objects in (ember 3.24) I am still seeing what look like problems, but you may be able to tell me that I'm doing it wrong.

See test project uploaded as https://github.com/flynnawtc/cs-test

The behaviour of the changeset appears to differ depending on whether an Ember-Data object is used or not.

When I construct a changeset as:

    let trunk = { branch: { leaf: null } };
    let leaf1 = {
      id: 1,
      description: 'leaf 1',
    };
    let cs = Changeset(trunk, null);
    cs.set('branch.leaf', leaf1);

then
I can use any of the following to get the same result ('leaf 1'):

cs.get('branch.leaf.description')
cs.get('branch.leaf').description
cs.get('branch.leaf').get('description')

However when I construct the changeset using ember-data:

    let trunk = this.store.createRecord('trunk');
    let branch = this.store.createRecord('branch');
    let leaf1 = this.store.createRecord('leaf', {
      id: 1,
      description: 'leaf 1',
    });
    trunk.branch = branch;
    let cs = Changeset(trunk, null);
    cs.set('branch.leaf', leaf1);

then this works, returning 'leaf 1':

cs.get('branch.leaf.description')

but these don't - they return 'undefined'

cs.get('branch.leaf').description
cs.get('branch.leaf').get('description')

I have tried constructing this as a test, but failed, hence the project referenced above.
Thanks again for your efforts which are much appreciated.
Regards
Adrian

@snewcomer
Copy link
Collaborator

@flynnawtc I think I might have your fix here.

adopted-ember-addons/validated-changeset#120

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants