You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've tried using the "most welcome" feature to be able to rollback a relationship in the cache after a record was added to a sync hasMany relationship (using store.cache.rollbackRelationships). This works fine the first time but the 2nd time the record is added and a rollback of the relation is attempted, the record is not removed from the collection.
I know it is a brand new feature, so I'm not sure if we can use it already or that I'm missing something here...
Reproduction
The last assert in following qunit test fails, after a 2nd attempt to rollback the relationship.
importModel,{attr,belongsTo,hasMany}from'@ember-data/model';import{setupTest}from'ember-qunit';import{module,test}from'qunit';letstore;module('integration/relationship/rollback relationship twice',function(hooks){setupTest(hooks);hooks.beforeEach(function(){classJobextendsModel{
@attrname;
@hasMany('message',{async: false,inverse: null})messages;}classMessageextendsModel{
@attrmsg;}store=this.owner.lookup('service:store');this.owner.register('model:job',Job);this.owner.register('model:message',Message);});/** test to verify that Ember Data issue https://github.com/emberjs/data/issues/8318 is fixed */test('rollback relationship twice',asyncfunction(assert){letjob;letmsg1;letjobs=awaitstore.push({data: [{id: '1',type: 'job',attributes: {name: 'First Job',},},],});letmsgs=awaitstore.push({data: [{id: '1',type: 'message',attributes: {msg: 'First Message',},},],});assert.equal(jobs.length,1);job=jobs[0];assert.equal(msgs.length,1);msg1=msgs[0];job.messages.push(msg1);assert.equal(job.messages.length,1,'job has 1 message');conststableRecordIdentifier=store.getReference('job',job.id).identifier();letrollbackRelations=store.cache.rollbackRelationships(stableRecordIdentifier);assert.equal(rollbackRelations.length,1,'1 rollbackRelations');assert.equal(job.messages.length,0,'job has no message');// repeat the scenario to add a message and rollbackjob.messages.push(msg1);assert.equal(job.messages.length,1,'job has 1 message');rollbackRelations=store.cache.rollbackRelationships(stableRecordIdentifier);assert.equal(rollbackRelations.length,1,'1 rollbackRelations');// 2nd time the relationship does not seem to be revertedassert.equal(job.messages.length,0,'job has no message');});});
@runspired Hi, at first I only tried the 5.3 but I've just redone the qunit test with the latest available version (5.5.0-alpha.11) and the result seems to be same (i.e. the last assert in the test fails)
@eodb our publish script has been borked for a while so we haven't actually published an alpha in some time. The fix I think affects this is only on main and in 4.12 (where rollback relationships wasn't available yet). We've also ported it to the 5.3 release branch but haven't published that fix yet in 5.3. Any chance you could PR the test?
Description
I've tried using the "most welcome" feature to be able to rollback a relationship in the cache after a record was added to a sync hasMany relationship (using store.cache.rollbackRelationships). This works fine the first time but the 2nd time the record is added and a rollback of the relation is attempted, the record is not removed from the collection.
I know it is a brand new feature, so I'm not sure if we can use it already or that I'm missing something here...
Reproduction
The last assert in following qunit test fails, after a 2nd attempt to rollback the relationship.
Versions
The text was updated successfully, but these errors were encountered: