question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Saving belongsTo() relationship doesn't work

See original GitHub issue

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', 'example@email.com');
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)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
andreyfelcommented, Jan 15, 2020

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

0reactions
andreyfelcommented, Jun 15, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

save a belongsTo relationship - php - Stack Overflow
I do not get any error but the model is not saved. I know there is the method associate , but I need...
Read more >
Can't save BelongsTo relationship · Issue #4482 - GitHub
Yes, when I create a new user, I can assign the role to him, but when I try to assign the same belongs...
Read more >
How to save model with two BelongsTo relations - Laracasts
I have a model theModel which belongsTo two other models: model1 and model2. So, in the_models table I have two foreign keys: model1_id...
Read more >
Associations - Sequelize
The A.hasOne(B) association means that a One-To-One relationship exists between A and B , with the foreign key being defined in the target...
Read more >
Eloquent: Relationships - The PHP Framework For Web Artisans
Eloquent makes managing and working with these relationships easy, ... We can define the inverse of a hasOne relationship using the belongsTo method:....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found