ember parse adapter hasMany错误

时间:2015-12-06 12:11:31

标签: ember.js parse-platform ember-data

在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有一个字段titleprice 对于这个数据库,我有以下模型:

应用/模型/ 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.

我不知道我需要指明哪种类型以及在何处进行操作 可能有人可以帮帮我吗?

我用:

  • ember 1.13.7
  • ember-data 1.13.8
  • ember-parse-adapter 0.5.3

1 个答案:

答案 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 }) 
});