尝试使用hasMany关系来保存()模型时,无法读取属性'determinRelationshipType' [英] Cannot read property 'determineRelationshipType' when trying to save() Model with hasMany Relationship
问题描述
当尝试使用具有hasMany关系的LocalStorage Adapter(使用Ember CLI)保存记录时,我遇到了一个棘手的错误。我想要做的是,当用户点击添加到包按钮时,将产品保存到包中。我的控制台出现这个错误:
未捕获TypeError:无法读取未定义的属性'determinRelationshipType'
/ p>
产品型号:
从ember-data导入DS;
导出默认DS.Model.extend({
...
包:DS.belongsTo('bag')
});
包包型号:
从ember-data导入DS;
导出默认DS.Model.extend({
产品:DS.hasMany('product',{async:true})
});
控制器中的操作如下:
从ember导入Ember;
导出默认Ember.ArrayController.extend({
actions:{
addToBag:function(model){
var bag = this.store.createRecord('bag ');
bag.get('products')然后(function(products){
products.pushObject(model);
bag.save();
}) ;
}
}
});
有谁会有什么想法出现了什么问题?还是另一种方法呢?看起来像一个类似的问题在这里被报告。非常感谢任何帮助!谢谢你提前。
我重新调查了这个问题,看起来像最近更新到余烬-localStorage的适配器
。具体来说, DS.RelationshipChange的引用已被删除。
在我的 bower.json
中,我定义了我的 ember-data
返回到 1.0.0-beta.11
,并将我的 ember-localstorage-adapter
版本定义为最新版本, 0.5.0
。以下是 bower.json
文件中的相关信息:
{
name:****,
dependencies:{
ember:1.8.1,
ember-data:1.0。 0-beta.11,
ember-localstorage-adapter:〜0.5.0,
}
}
此错误不再出现!
I'm running into a tough bug when trying to save a record with the LocalStorage Adapter that has a hasMany relationship (Using Ember CLI). What I'm trying to do is save a product to a bag when a user clicks on a "Add to Bag" button. I'm getting this error in my console:
Uncaught TypeError: Cannot read property 'determineRelationshipType' of undefined
Product Model:
import DS from 'ember-data';
export default DS.Model.extend({
...
bag: DS.belongsTo('bag')
});
Bag Model:
import DS from 'ember-data';
export default DS.Model.extend({
products: DS.hasMany('product', {async: true})
});
Here's the action in the controller:
import Ember from "ember";
export default Ember.ArrayController.extend({
actions: {
addToBag: function(model) {
var bag = this.store.createRecord('bag');
bag.get('products').then(function(products) {
products.pushObject(model);
bag.save();
});
}
}
});
Would anyone have an idea as to what's going wrong? Or another way to approach this? Seems like a similar issue was reported here. Would greatly appreciate any help! Thank you in advance.
I re-investigated this issue and looks like it was addressed in a recent update to ember-localstorage-adapter
. Specifically, the reference to DS.RelationshipChange was removed.
In my bower.json
, I defined my ember-data
version back to 1.0.0-beta.11
and also defined my ember-localstorage-adapter
version to the latest version, 0.5.0
. Here's the relevant info in the bower.json
file:
{
"name": "****",
"dependencies": {
"ember": "1.8.1",
"ember-data": "1.0.0-beta.11",
"ember-localstorage-adapter": "~0.5.0",
}
}
This error is no longer appearing!
这篇关于尝试使用hasMany关系来保存()模型时,无法读取属性'determinRelationshipType'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!