私Post
は多くComment
の s を持つモデルを持っています。の応答GET /posts/12
は、かなり Ember-Data に適しています。
{
"post": {
"id": 12,
"title": "I Love Ramen",
"created_at": "2011-08-19T14:22",
"updated_at": "2011-08-19T14:22",
"body": "..."
}
}
ただし、そのPost
の のAPIは であり、これは次を返しますComment
GET /posts/12/comments
{
"comments": [
{
"id": 673,
"author_id": 48,
"created_at": "2011-08-21T18:03",
"body": "Me too!"
}
]
}
Post 12
モデルまたはアダプタに対して、のComment
に を使用することを伝えるにはどうすればよい/posts/12/comments
ですか? Post
自体はComment
IDを認識していないことに注意してください。
アップデート
buuda の回答に応じて、いくつかの説明があります。
は、(a)のコメントを表示し、(b) のようなプロパティを持つことができるように、Post
その を検索できる必要があります。Comment
PostRoute
Post
hasComments: function() {
return this.get('comments.length') > 0;
}.property('comments')
comments
ただし、計算されたプロパティを実装する必要がある場合は問題ありません。上記の回答で、ブダは示唆しています
App.Comments.find({ id: postId });
/posts/:postId/comments
の代わりにデータストアを取得するにはどうすればよい/comments?postId=:postId
ですか?