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

Saving belongsTo() relationship doesn't work #403

Closed
andreyfel opened this issue Jan 13, 2020 · 6 comments
Closed

Saving belongsTo() relationship doesn't work #403

andreyfel opened this issue Jan 13, 2020 · 6 comments

Comments

@andreyfel
Copy link
Contributor

Version

ember-changeset@^3.0.0-beta.9

Test Case

Profile model:

class Profile extends Model {
  @attr('string') name;
}

User model:

class User extends Model {
  @attr('string') email;
  @belongsTo('profile') profile;
}

Creating a user with a profile and saving it:

const profiles = await this.store.finsAll('profile');
const user = this.store.createRecord('user');
const changeset = new Changeset(user, ...);
changeset.set('email', '[email protected]');
changeset.set('profile', profile[0]);
changeset.save();

Expected Behavior

User is saved

Actual Behavior

An exception is thrown:

Uncaught (in promise) Error: Assertion Failed: Cannot call set with 'name' on an undefined object.
    at assert (index.js:128)
    at _set2 (index.js:2632)
    at setPath (index.js:2692)
    at Object._set2 [as safeSet] (index.js:2642)
    at merge-deep.js:92
    at Array.forEach (<anonymous>)
    at mergeTargetAndSource (merge-deep.js:81)
    at mergeDeep (merge-deep.js:150)
    at Proxy.execute (index.js:196)
    at Proxy._callee$ (validated-changeset.js:261)
@andreyfel
Copy link
Contributor Author

Changeset contains ember model in the profile field and apparently it tries to make a deep copy of it on save.

@andreyfel
Copy link
Contributor Author

I've modified one test to illustrate the issue in the testuite: #405

Error: Assertion Failed: Cannot delegate set('firstName', Grace) to the 'content' property of object proxy <(unknown):ember183>: its 'content' is undefined.
    at assert (http://localhost:7357/assets/vendor.js:38210:15)
    at Proxy.setUnknownProperty (http://localhost:7357/assets/vendor.js:27561:48)
    at set (http://localhost:7357/assets/vendor.js:17273:11)
    at setPath (http://localhost:7357/assets/vendor.js:17301:14)
    at Object.set [as safeSet] (http://localhost:7357/assets/vendor.js:17248:14)
    at http://localhost:7357/assets/vendor.js:67256:23
    at Array.forEach (<anonymous>)
    at mergeTargetAndSource (http://localhost:7357/assets/vendor.js:67245:21)
    at mergeDeep (http://localhost:7357/assets/vendor.js:67312:14)
    at Proxy.execute (http://localhost:7357/assets/vendor.js:66796:48)

@snewcomer
Copy link
Collaborator

snewcomer commented Jan 15, 2020

@andreyfel ref #406 Did this PR fix the issue you were looking at? 3.0.0-beta.10

@andreyfel
Copy link
Contributor Author

@snewcomer I rebased my failing test branch and it still fails.
I think I found an issue, will submit a PR tomorrow.

@snewcomer
Copy link
Collaborator

@andreyfel Mind checking out the latest release and let me know if this is fixed!?!

@andreyfel
Copy link
Contributor Author

Seems it is no longer an issue with the latest build! Thanks a lot @snewcomer!

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

No branches or pull requests

2 participants