samedi 16 septembre 2017

Load relationship model in Ember data

I have certain doubts with respect to Ember Data. I have a post and comments model.

//post.js
comments: DS.hasMany('comment')

//blog.js
post: DS.belongsTo('post')

I can create a comment for a particular "post" using

let blogPost = this.get('store').findRecord('post', 1);
let comment = this.get('store').createRecord('comment', {
   post: blogPost
});

But how can i fetch all the comments for a particular post? Like, I have multiple posts which has many comments and i want all the comments for a particular post id, say posts/id/comments

What is the right way to fetch the comments for a particular post id from the store?

Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire