根据
spec
,
resource identifier objects
不要保留属性。
我想做一篇文章来创建一个包含其他嵌套资源的新资源。
这些是基本资源:
俱乐部
用
名称
和许多
位置
(
类型
)想想一个足球俱乐部的位置,比如守门员,守门员,前锋,前锋等等。
当我做这个关联时,我想设置一些属性,比如这个特定团队所需的位置。例如,我只需要一个守门员,但我想有一支有很多预备队守门员的球队。当我在数据库中对这些实体建模时,我将在链接表中设置必需的属性。
这与JSON API不兼容:
json
{
"data": {
"type": "club",
"attributes": {
"name": "Backyard Football Club"
},
"relationships": {
"positions": {
"data": [{
"id": "1",
"type": "position",
"attributes": {
"required": "true"
}
}, {
"id": "1",
"type": "position",
"attributes": {
"required": "false"
}
}
]
}
}
}
}
这也无效:
json
{
"data": {
"type": "club",
"attributes": {
"name": "Backyard Football Club",
"positions": [{
"position_id": "1",
"required": "true"
},
{
"position_id": "1",
"required": "false"
}]
}
}
}
那么,如何才能最好地接近这个协会呢?