adopted-ember-addons / ember-changeset

Ember.js flavored changesets, inspired by Ecto
http://bit.ly/ember-changeset-demo
MIT License
431 stars 141 forks source link

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

Closed flynnawtc closed 3 years ago

flynnawtc commented 3 years ago

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 commented 3 years ago

@flynnawtc I think I might have your fix here.

https://github.com/validated-changeset/validated-changeset/pull/120