I am new to Sequalize. Tried to figure this out but cant wrap my head around how it works. So I need to JOIN three tables based on two others

I have my models defined by sequelize-auto. Here is my init-models file

`var DataTypes = require("sequelize").DataTypes; var _lesson_students = require("./lesson_students"); var _lesson_teachers = require("./lesson_teachers"); var _lessons = require("./lessons"); var _students = require("./students"); var _teachers = require("./teachers"); function initModels(sequelize) { var lesson_students = _lesson_students(sequelize, DataTypes); var lesson_teachers = _lesson_teachers(sequelize, DataTypes); var lessons = _lessons(sequelize, DataTypes); var students = _students(sequelize, DataTypes); var teachers = _teachers(sequelize, DataTypes); lesson_students.belongsTo(lessons, { as: "lesson", foreignKey: "lesson_id"}); lessons.hasMany(lesson_students, { as: "lesson_students", foreignKey: "lesson_id"}); lesson_teachers.belongsTo(lessons, { as: "lesson", foreignKey: "lesson_id"}); lessons.hasMany(lesson_teachers, { as: "lesson_teachers", foreignKey: "lesson_id"}); lesson_students.belongsTo(students, { as: "student", foreignKey: "student_id"}); students.hasMany(lesson_students, { as: "lesson_students", foreignKey: "student_id"}); lesson_teachers.belongsTo(teachers, { as: "teacher", foreignKey: "teacher_id"}); teachers.hasMany(lesson_teachers, { as: "lesson_teachers", foreignKey: "teacher_id"}); // removing unused ids lesson_students.removeAttribute('id') lesson_teachers.removeAttribute('id') return { lesson_students, lesson_teachers, lessons, students, teachers, }; } module.exports = initModels; module.exports.initModels = initModels; module.exports.default = initModels; `

Result eventually should be an object with populated fields. It should look like something like this

`{ id : 9 date: ‘2019-09-01’ title: ‘Orange’, status: 1 students: [ // populated array of students { id: 1, name: ‘John’ visit: true, }], teachers: [ // populated array of teachers { id: 1, name: ‘Alice’ }] } `

At the moment i figured out how to get this result

`{ id: 10, date: '2019-06-24', title: 'Brown Color', status: 0, lesson_teachers: [ [lesson_teachers] ], lesson_students: [ [lesson_students] ] } `

by following code

`resultLessons = await models.lessons.findAll({ include: [{ model: models.lesson_teachers, as: 'lesson_teachers', }, { model: models.lesson_students, as: 'lesson_students' }], }) const lessons = resultLessons.map((lesson) => (lesson.dataValues)) console.log(lessons) `

So question is how do I populate [lesson_teachers] and [lesson_students] with actual data? (like method .populate in mongoose)

Thanks a lot in advance