I have 2 models, a post model and a comment model. I would like to download the comments asynchronously, and it works fine with the following models.
//models/post.js
export default DS.Model.extend({
date: attr('string'),
user: belongsTo('user'),
comments: hasMany('comment', {async: true})
});
//models/comment.js
export default DS.Model.extend({
date: attr('string'),
user: belongsTo('user'),
value: attr('string')
});
Although sometimes, a post can have hundreds of comment ids returned, and I don’t want to load all the comments in one shot, this can be too big, so I’d like to limit the request to the ids that I want first.
If I am doing the following, it will download all the comments at once.
this.store.findRecord('post', 1).then((post) => {
post.get('comments'); //Will call the server to load all the comments
});
I was thinking to get the list of ids I got, slice the array to get the first 10 comments and send the request that way, but I’m not even able to access the ids, as when I call .get('comments')
it loads them all.
I’m wondering what could be my best solution to avoid to load all the comments in one shot?
Thanks