Uncaught #<error> on loading fixtures
-
21-12-2019 - |
Question
I'm doing something wrong with fixtures. I have to models where a Contract has many Contractitems and try to load fixtures for them
App.Contract = DS.Model.extend({
contractItems: DS.hasMany('contractItem'),
//
});
App.ContractItem = DS.Model.extend({
contract: DS.belongsTo('contract'),
//
});
App.Contract.FIXTURES = [{
id: 1,
runtime: 12,
//
contractItems: [1, 2]
},{
id: 2,
//
}];
App.ContractItem.FIXTURES = [{
id: 1,
//
},{
id: 2,
//
}];
I commented out some dull attrubutes, but the full file is up here. When I load the page, i get an Error
Uncaught #<error> VM1615:956
ProfileManager.ended VM1615:956
Ember.subscribe.after VM1615:2007
finalizer ember-1.5.1.js:1802
Ember.tryCatchFinally ember-1.5.1.js:1554
Ember.Instrumentation.instrument ember-1.5.1.js:1810
Ember.CoreView.Ember.Object.extend.renderToBuffer ember-1.5.1.js:22472
Ember.View.Ember.CoreView.extend.createElement ember-1.5.1.js:23993
Ember.merge.insertElement ember-1.5.1.js:24944
Ember.View.Ember.CoreView.extend._insertElement ember-1.5.1.js:23921
DeferredActionQueues.flush ember-1.5.1.js:6125
Backburner.end ember-1.5.1.js:6215
Backburner.run ember-1.5.1.js:6254
executeTimers ember-1.5.1.js:6552
(anonymous function)
Removing the line contractItems: [1, 2]
resolves this, but obviously the related objects are not loaded then.
I thought, I did something wrong with camelcasing and tried different versions, but no success.
Ember is used in version 1.5.1, Ember-Data in version 1.0.0-beta9.
Any hints are welcome...
Solution
You're relationships will need to be defined as async since they aren't loaded in the same payload as the record you are loading.
App.Contract = DS.Model.extend({
contractItems: DS.hasMany('contractItem', {async:true}),
//
});
App.ContractItem = DS.Model.extend({
contract: DS.belongsTo('contract', {async:true}),
//
});
Remember when accessing async properties to use then
contract.get('contractItems').then(function(items){
console.log(items.get('length'));
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow