How to include model in through query

38 views
Skip to first unread message

Алексей Данчин

unread,
Nov 25, 2017, 6:34:30 PM11/25/17
to Sequelize
Hi! I have some relations for Lesson, User and Homework models:

Lesson.belongsToMany(User, { as: 'member', through: LessonMember });
User.belongsToMany(Lesson, { through: LessonMember });
LessonMember.belongsTo(Homework);


And I want to findAll Lesson, include members with together with their homework.

Lesson.findAll({
 include
: [{
  model
: User,
 
as: 'member',
  through
: {
   include
: [{
    model
: Homework
   
}]
 
}
 
}]
})

But I real i get error: InternalServerError: Cannot read property 'indexOf' of undefined
How right? How get Lessons with members and homeworks?

For clarity: the code below works as expected.
Lesson.findAll({
 include
: [{
  model
: User,
   
as: 'member',
   through
: {
 
  attributes: ['homeworkId']
   
}
 
}]
})

Reply all
Reply to author
Forward
0 new messages