Answer the question
In order to leave comments, you need to log in
How to do 1:n eager loading in Sequelize?
Hello. Trying to implement a 1:n relationship in sequelize.
Made according to the example docs.sequelizejs.com/manual/associations.html#1-n ,
Comment.belongsTo(models.Post, {
foreignKey: 'commentableId',
constraints: false,
as: 'post'
});
Comment.belongsTo(models.Event, {
foreignKey: 'commentableId',
constraints: false,
as: 'event'
});
let comments = await queryComments.findAll({
include: [
{
as: "authorData",
model: models.User,
attributes: ['id', 'name']
},
{
association: '', //как сюда подставить правильную ассоциацию? Полагаю, this.commentable работать не будет никак
}
],
attributes: ['id','author','createdAt','parentId','commentable','commentableId'],
...pagination.pagesQuery
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question