我有一个模型,Post有很多Comments。的响应GET /posts/12非常适合 Ember 数据:
{
"post": {
"id": 12,
"title": "I Love Ramen",
"created_at": "2011-08-19T14:22",
"updated_at": "2011-08-19T14:22",
"body": "..."
}
}
Post但是,该s的 APIComment是GET /posts/12/comments,它返回
{
"comments": [
{
"id": 673,
"author_id": 48,
"created_at": "2011-08-21T18:03",
"body": "Me too!"
}
]
}
我可以对我的模型或适配器做些什么来告诉它 for Post 12s Comment, use /posts/12/comments?请注意,它Post本身不知道CommentID。
更新
针对buuda 的回答,这里有一些说明:
ThePost必须能够查找它Comment的 s 以便我可以(a)显示对 the 的评论PostRoute和(b)在Postlike上有属性
hasComments: function() {
return this.get('comments.length') > 0;
}.property('comments')
不过,如果我必须实现comments计算属性,这对我来说很好。在上述答案中,布达建议
App.Comments.find({ id: postId });
如何获取数据存储/posts/:postId/comments而不是fetch /comments?postId=:postId?