Is it possible to include a model for an attribute of a many-to-many relation via through?
Let's say I'm having the following Models:
User = sequelize.define('user', {/* attributes */});
Question = sequelize.define('question', {/* attributes */});
Answer = sequelize.define('answer', {/* attributes */});
/* Where */
Question.hasMany(Answer);
Answer.belongsTo(Question);
I'd like to save for every user which answer he gave to a question. So I added the following relation:
UserQuestionAnswerRel = sequelize.define('usersAnwers', {
user: {/**/},
question: {/**/},
answer: {/**/}
});
User.hasMany(Question, { through: UserQuestionAnswerRel });
Now I'd like to query a user receiving all questions he answered and the answer he gave. But how does that work? Unfortunately this doesn't work:
User.findAll({
include: {
model: Question,
through: { include: model.Answer }
}
}).then /* */
Please note: All this Q&A stuff is just an example. It won't be possible for me to not use a through relation.
through? This should be pretty straight forward to do with Nested eager loading... - Will