In a unit test:
import ServicesProductHoldingBookEngineerMixin from 'ember-commons/models/services-product-holding-book-engineer-mixin';
moduleForModel('appointment', {
needs: [/*...*/],
beforeEach() {
let store = this.store();
let servicesProductHoldingModel = store.modelFor('servicesProductHolding');
let servicesProductHoldingModel2 = servicesProductHoldingModel.extend(ServicesProductHoldingBookEngineerMixin);
getOwner(store).unregister('model:services-product-holding');
getOwner(store).register('model:services-product-holding', servicesProductHoldingModel2);
let sph = store.createRecord('servicesProductHolding');//not extended
console.log('test mixin', sph.get('productDisplayName'));//'productDisplayName' is a property of the mixin, so I expect to see it - except not.
}
});
Part of the solution is to manually delete the factoryCache:
let container=getOwner(this).__container__;
delete container.factoryCache['model:services-product-holding']
but then the relationships of the previously registered model are not properly cleared:
You defined the 'faults' relationship on dummy@model:services-product-holding:, but multiple possible inverse relationships of type dummy@model:services-product-holding: were found on dummy@model:fault
UPDATE: this is due in a bug on Ember-Data 2.10 in https://github.com/emberjs/data/blob/v2.10.0/addon/-private/system/relationships/ext.js#L311 not linked to this issue so deleting the container factoryCache is above is indeed the right solution.
So basically https://github.com/emberjs/ember.js/issues/11173 is current again
I suspect on master the cache that needs to be cleared is named differently https://github.com/emberjs/ember.js/blob/master/packages/container/lib/container.js#L35
@bekzod got any cycles to lend a hand on this one?
Sure, will look at
@Leooo which version of ember you were looking at ?
Ember & ED 2.10
@Leooo tried following test https://cl.ly/3e2w2I3U2A0l in ember 2.10.0, 2.10.2 and master it does not fail, it might be ember data issue
I also have manually checked everything works, cannot reproduce
https://cl.ly/0e0z2B2K0j2T/Screen%20Shot%202017-05-23%20at%202.27.36%20AM.jp2
Ember 2.10.2
Ember Data 2.10.0
@bekzod ok strange, leave this open I will try to create a failing test in the next days, probably with Ember Data indeed (in which case it will go into the the ED repo I suppose).
Thanks a lot for checking,
L
@bekzod @stefanpenner added failing test in https://github.com/emberjs/data/pull/4999
While poking at this I beefed up some of Ember's tests around owner.unregister here. It seems that all is working well on the Ember side, so I'm going to close this and we can dig into the Ember Data issue over in https://github.com/emberjs/data/pull/4999 and https://github.com/emberjs/data/issues/5000.
I followed up on this here: https://github.com/emberjs/data/issues/5000#issuecomment-383337040
Most helpful comment
Sure, will look at