I need to load a model from a rail backend using ember-data and its default REST adapter. I have a model that has many relationships with another:
App.Post = DS.Model.extend({
title: DS.attr("String");
comments: DS.hasMany('App.Comment', {keys: 'post_ids', embbeded: true});
})
App.Post = DS.Model.extend({
body: DS.attr("String");
post: DS.belongsTo('App.Post');
})
The JSON model returned by the server looks like
{
title: "a title",
comment_ids: [1,2,3,4]
}
I need to download all posts first without having to download related comments for efficiency reasons. I do it with
App.store.findAll('App.Post');
And, when I select a specific post, I need to download all the comments. In the documentation for ember-data, he said I just need to call
a_specific_post.get('comments')
When, I do this, I get a very long url with all the comments:
GET : /comments?ids%all_ids_appended_here
Of course, this will not work, and if I have a thousand comments, the URL is very long.
Is it possible to get a request that matches the nested rail routing model?
GET /posts/post_id/comments
- https://github.com/ghempton/ember-routemanager . ember ?