我在将来自 Grape(用 Grape 实体序列化)的 Json 有效负载与 Ember 反射模型连接时遇到问题。模型看起来像这样:
Category = DS.Model.extend {
name: DS.attr 'string',
children: DS.hasMany 'category', inverse: 'parent',
parent: DS.belongsTo 'category', inverse 'children'
}
Run Code Online (Sandbox Code Playgroud)
因此,正如您所看到的,我正在尝试对类别-子类别关系进行建模。来自端点的示例 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
}
]
} …Run Code Online (Sandbox Code Playgroud)