【发布时间】:2017-06-09 13:56:05
【问题描述】:
在进行 API 调用时,我无法卸载数据模型并正确地重新填充它们。
模型:
/* Model Foo */
export default DS.Model.extend({
bars: DS.hasMany('bar', { async: true })
});
/* Model Bar */
export default DS.Model.extend({
foo: DS.belongsTo('foo', { async: true, inverse: 'bars' })
});
在应用程序中的某个时间点,foo 和 bar 都从 ember 数据存储中卸载,然后从 API 调用中重新加载。像这样:
/* Unload and reload snippet */
this.store.unloadAll('bar');
this.store.unloadAll('foo');
let bars = this.store.filter('bar', {
queryParam: x
}, function(bar) {
return x === bar.x
});
let foos = this.store.filter('foo', {
queryParam: y
}, function(foo) {
return y === bar.y
});
let self = this;
Ember.RSVP.all([foos, bars]).finally(function() {
self.controller.set('model.foos', foos);
self.controller.set('model.bars', bars);
});
问题出现在依赖于这些模型更改的计算属性中。
/* Computed property elsewhere in app */
compProp: Ember.computed('foo.bars.[]', function() {
let tmp = this.get('foo.bars'); /* <-- Error generating line */
.
.
.
})
这一行给了我以下错误:
Assertion Failed: calling set on destroyed object: <DS.PromiseManyArray:ember1995>.content = <DS.ManyArray:ember3320>
错误的堆栈跟踪:
Assertion Failed: calling set on destroyed object: <DS.PromiseManyArray:ember1014>.content = <DS.ManyArray:ember1348>
Error
at assert (http://localhost:4200/assets/vendor-3e8430b320dbe268f7ee6486de4c6cad.js:23072:13)
at Object.assert (http://localhost:4200/assets/vendor-3e8430b320dbe268f7ee6486de4c6cad.js:23285:34)
at Object.set (http://localhost:4200/assets/vendor-3e8430b320dbe268f7ee6486de4c6cad.js:39281:17)
at Class.set (http://localhost:4200/assets/vendor-3e8430b320dbe268f7ee6486de4c6cad.js:52151:26)
at ManyRelationship._updateLoadingPromise (http://localhost:4200/assets/vendor-3e8430b320dbe268f7ee6486de4c6cad.js:152522:33)
at ManyRelationship.getRecords (http://localhost:4200/assets/vendor-3e8430b320dbe268f7ee6486de4c6cad.js:152723:21)
at Class.get (http://localhost:4200/assets/vendor-3e8430b320dbe268f7ee6486de4c6cad.js:152101:60)
at ComputedPropertyPrototype.get (http://localhost:4200/assets/vendor-3e8430b320dbe268f7ee6486de4c6cad.js:34367:28)
at get (http://localhost:4200/assets/vendor-3e8430b320dbe268f7ee6486de4c6cad.js:39184:19)
at _getPath (http://localhost:4200/assets/vendor-3e8430b320dbe268f7ee6486de4c6cad.js:39205:13)
at Object.get (http://localhost:4200/assets/vendor-3e8430b320dbe268f7ee6486de4c6cad.js:39180:14)
感谢您的帮助!
旁注:
- 我知道
store.filter()已被弃用。我正在从早期的 Ember 版本升级应用程序,并使用 ember-data-filter 插件来实现临时兼容性。 - 这适用于 Ember 1.13。
更新
为了不让这个问题悬而未决,我一直无法找到问题。
我的解决方案是删除所有 unloadAll() 呼叫并根据需要单独管理记录。
【问题讨论】:
标签: ember.js ember-data