在parse.com上的数据库中,我有一个表Item
,其中包含以下字段:
"objectId": "O0NkhZAcMd",
"price": "100",
"topping": [
{
"__type": "Pointer",
"className": "Topping",
"objectId": "iKbMWHZrEB"
},
{
"__type": "Pointer",
"className": "Topping",
"objectId": "yIIkePYKSS"
},
{
"__type": "Pointer",
"className": "Topping",
"objectId": "lZJ4Kpqodf"
},
...
]
Topping有一个字段title
和price
对于这个数据库,我有以下模型:
应用/模型/ item.js:
import DS from 'ember-data';
export default DS.Model.extend({
objectId: DS.attr(),
price: DS.attr(),
topping: DS.hasMany('topping', {async: true}),
});
应用/模型/ topping.js:
import DS from 'ember-data';
export default DS.Model.extend({
objectId: DS.attr(),
price: DS.attr(),
title: DS.attr(),
});
当我在topping: DS.hasMany('topping', {async: true})
中添加app/models/item.js
时,我开始收到以下错误:
Error while processing route: menu Assertion Failed: Ember Data expected a number or string to represent the record(s) in the `topping` relationship instead it found an object. If this is a polymorphic relationship please specify a `type` key. If this is an embedded relationship please include the `DS.EmbeddedRecordsMixin` and specify the `topping` property in your serializer's attrs object.
我不知道我需要指明哪种类型以及在何处进行操作 可能有人可以帮帮我吗?
我用:
答案 0 :(得分:0)
尝试将belongs_to
关系添加到您的topping
模型。
import DS from 'ember-data';
export default DS.Model.extend({
objectId: DS.attr(),
price: DS.attr(),
title: DS.attr(),
item: DS.belongsTo('item', { async: true })
});