4
我在使用Ember反射模型连接来自Grape(使用Grape实体序列化)的Json有效载荷时出现问题。模式是这样的:如何使用Ember自反模型连接Rails Grape API
Category = DS.Model.extend {
name: DS.attr 'string',
children: DS.hasMany 'category', inverse: 'parent',
parent: DS.belongsTo 'category', inverse 'children'
}
因此,大家可以看到,我想在这里模拟类,子类关系。从端点示例JSON响应是:
{
"category": {
"id": 1,
"name": "Sport",
"child_ids": [
5,
6,
8,
7
]
},
"children": [
{
"id": 5,
"name": "Basketball",
"parent_id": 1
},
{
"id": 6,
"name": "Football",
"parent_id": 1
},
{
"id": 8,
"name": "Running",
"parent_id": 1
},
{
"id": 7,
"name": "Volleyball",
"parent_id": 1
}
]
}
有是警告消息:
WARNING: Encountered "children" in payload, but no model was found for model name "child" (resolved model name using [email protected]:-active-model:.modelNameFromPayloadKey("children"))
,因为它说在文档ActiveModelAdapter它应该提供用于与侧载数据父资源嵌套的资源和id标识。问题是在余烬检查员中有一个类别记录,但没有相关的孩子。我已经试过做两个模型:类别和子类别,并提供相同的有效载荷与其他ids/id namings,我可以看到,在这种情况下,有所有需要的子类别记录,但没有为许多类别(两个分离数据)。