【发布时间】:2016-03-16 11:03:58
【问题描述】:
http://jsonapi.org/format/#fetching-includes
文章属于作者。文章有很多cmets。评论属于用户。
试图了解如何包含嵌套关系。举个例子:https://www.foo.com/articles?include=comments
你会期望:
{
data: [
{
id: 1,
type: "articles",
attributes: { ... },
relationships: {
author: { ... },
comments: [{ ... }, { ... }],
},
...
},
{ ... }
]
included: [
{
author: { ... },
comment: { ... },
comment: { ... }
{
]
}
现在让我们说,您想包括编写这些 cmets 的用户。 https://www.foo.com/articles?include=comments.user
响应应该是这样的:
{
data: [
{
id: 1,
type: "articles",
attributes: { ... },
relationships: {
author: { ... },
comments: [{ ... }, { ... }]
},
...
},
{ ... }
]
included: [
{
author: { ... },
comment: { ... },
comment: { ... },
user: { ... },
user: { ... }
{
]
}
users(编写 cmets 的用户)也应该在 relationship 节点中,还是只在 included 节点中?
如果在relationship 节点中。 user 是否应该嵌套在 data.relationships.comments 中?看起来怎么样?
【问题讨论】:
标签: ember.js ember-data json-api