Saving belongsTo() relationship doesn't work
See original GitHub issueVersion
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:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@snewcomer I rebased my failing test branch and it still fails. I think I found an issue, will submit a PR tomorrow.
Seems it is no longer an issue with the latest build! Thanks a lot @snewcomer!