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,我可以看到,在這種情況下,有所有需要的子類別記錄,但沒有爲許多類別(兩個分離數據)。