Starting with ember-data version 3.12.0, setting a belongsTo relationship property on a model is not working after that relationship previously rejected. As an example, if an async fetch of a post's user returns a 404, I'm then catching the error, creating a new user, and setting it to the post:
async fetchOrCreateUser() {
try {
await this.post.get('user');
} catch (error) {
// 404 returned. Create a new user and set it as the post's user
const newUser = this.store.createRecord('user', {
name: 'Larry',
});
this.post.set('user', newUser);
}
},
this.post.user is now the new user
this.post.user continues to be the rejected promise from the first get
I'm pretty sure this has to do with this change: https://github.com/emberjs/data/pull/6112
This issue does not occur in version 3.11.5 and below.
yarn && yarn startNotice that the user name never populates, and isRejected is always true
yarn && yarn startNotice that the user name does populate successfully
yarn list v1.19.1
warning Filtering by arguments is deprecated. Please use the pattern option instead.
โโ [email protected]
โจ Done in 0.62s.
yarn list v1.19.1
warning Filtering by arguments is deprecated. Please use the pattern option instead.
โโ [email protected]
โจ Done in 0.63s.
yarn list v1.19.1
โโ @ember-data/[email protected]
โโ @ember-data/[email protected]
โโ @ember-data/[email protected]
โโ @ember-data/[email protected]
โโ @ember-data/[email protected]
โโ @ember-data/[email protected]
โโ @ember-data/[email protected]
โโ [email protected]
yarn list v1.19.1
warning Filtering by arguments is deprecated. Please use the pattern option instead.
โโ [email protected]
โจ Done in 0.67s.
yarn list v1.19.1
warning Filtering by arguments is deprecated. Please use the pattern option instead.
โโ [email protected]
โจ Done in 0.61s.
yarn list v1.19.1
โโ @ember-data/[email protected]
โโ @ember-data/[email protected]
โโ @ember-data/[email protected]
โโ @ember-data/[email protected]
โโ @ember-data/[email protected]
โโ @ember-data/[email protected]
โโ [email protected]
Thanks! If you have time to turn your reproduction into a test scenario that would be awesome, but regardless thanks for the report.
cc @code0100fun let's roll this into the unload work since it's a similar issue to what you started out working on.
Hi, @runspired, thanks for your response! Yeah, I'll try to get a test scenario written early this week
@runspired - Here you go: https://github.com/emberjs/data/pull/6874
Also faced with this issue during the upgrade to 3.12. I assume this behaviour is related:
> record.set('myRelation', null)
null
> record.myRelation
Proxy {isFulfilled: false, isRejected: false, content: null, _belongsToState: {โฆ}, _super: ฦ}
@veelenga your example above seems like correct behavior, content is null
Hey there @runspired and @code0100fun . Just checking to see if there is an ETA on this one yet
@runspired G'day mate is there any movement here. Or is there a better way for us to move forward?
I loved the sit ups and your dog video.
Most helpful comment
Hey there @runspired and @code0100fun . Just checking to see if there is an ETA on this one yet