Archived
1
0
This repository has been archived on 2022-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
moyklass.com/sequelize/extra-setup.js
2022-06-03 00:56:12 +03:00

31 lines
727 B
JavaScript

function applyExtraSetup(sequelize) {
const { lessons, students, teachers, lesson_students, lesson_teachers } = sequelize.models;
lessons.belongsToMany(students, {
as: "students",
through: lesson_students,
foreignKey: "lesson_id",
otherKey: "student_id",
});
lessons.belongsToMany(teachers, {
as: "teachers",
through: lesson_teachers,
foreignKey: "lesson_id",
otherKey: "teacher_id",
});
students.belongsToMany(lessons, {
as: "lessons",
through: lesson_students,
foreignKey: "student_id",
otherKey: "lesson_id",
});
teachers.belongsToMany(lessons, {
as: "lessons",
through: lesson_teachers,
foreignKey: "teacher_id",
otherKey: "lesson_id",
});
}
module.exports = { applyExtraSetup };