【发布时间】:2013-09-17 02:38:47
【问题描述】:
这是我的 Ember-Data 模型:
Lrt.Option = DS.Model.extend({
option_relation_value: hasMany('option')
});
这是 JSON 的一个示例:(为了这个问题而缩短)
{
"optionGroups": [],
"optionSubGroups": [
{
"id": "3",
"optionType": [
"80",
"81",
"82",
"83",
"84",
"248",
"278"
],
"title": "Option Group for 80"
}
],
"options": [
{
"id": "45",
"option_relation_value": [
"80"
]
},
{
"id": "80",
"option_relation_value": []
}
]
}
还有“OptionGroup”和“OptionSubGroup”模型,它们是侧载选项。
我遇到的问题是,在将“hasMany”添加到模型中后,我无法再在商店中查询这样的选项:
this.get('store').find('option')
它只是返回“0”,但是在 Ember Inspector 中,我得到了 400 多个条目,所以我知道加载的数据。
当使用 chrome 检查器并在 ALL Exceptions 上中断时,它会在 Ember-Data 的第 2246 行的以下行中断:
2246: Ember.assert('The id ' + id + ' has already been used with another record of type ' + type.toString() + '.', !id || !idToRecord[id]);
错误是:
"Cannot call method 'toString' of undefined"
这一行中的“type”是'undefined'。
我在这种 hasMany 关系中做错了什么?
我正在使用 Ember-Data 1.0 Beta 2。
【问题讨论】:
标签: ember.js ember-data