我有2个模型,一个帖子模型和一个评论模型。我想异步下载注释,它可以与以下模型一起使用。
//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')
});
虽然有时候,帖子可能有数百个评论ID,而且我不想一次性加载所有评论,这可能太大了,所以我想限制请求。
如果我这样做,它会立即下载所有评论。
this.store.findRecord('post', 1).then((post) => {
post.get('comments'); //Will call the server to load all the comments
});
我甚至无法访问ID以手动通过商店,因为当我致电.get('comments')
时,它会将它们全部加载。
我想知道什么是我最好的解决方案,以避免一次性加载所有评论?
由于