What is the difference between these two usages of ManyArray
? Is one more correct than the other? Does it matter?
//app/models/post.js
export default DS.Model.extend({
comments: DS.hasMany('comment')
});
//app/models/comment.js
export default DS.Model.extend({
post: DS.belongsTo('post')
});
// Usage 1: Access a post's comments directly
post.get('comments.length');
post.get('comments').forEach((comment) => {
// Do something with comment here
});
post.get('comments').pushObject(pushThisComment);
post.get('comments').removeAt(removeTheCommentAtThisIndex);
// Usage 2: Access a post's comments after promise resolves
post.get('comments').then((comments) => {
comments.get('length');
comments.forEach((comment) => {
// Do something with comment here
});
comments.pushObject(pushThisComment);
comments.removeAt(removeTheCommentAtThisIndex);
});