Sequelize UI

  • student-info-system
    • models
import type { Sequelize, Model } from 'sequelize'
import { Student } from './Student'
import { Teacher } from './Teacher'
import { Course } from './Course'
import { CourseSection } from './CourseSection'
import { CourseSectionEnrollment } from './CourseSectionEnrollment'
import { CourseSectionPosition } from './CourseSectionPosition'
import { Topic } from './Topic'
export {
Student,
Teacher,
Course,
CourseSection,
CourseSectionEnrollment,
CourseSectionPosition,
Topic
}
export function initModels(sequelize: Sequelize) {
Student.initModel(sequelize)
Teacher.initModel(sequelize)
Course.initModel(sequelize)
CourseSection.initModel(sequelize)
CourseSectionEnrollment.initModel(sequelize)
CourseSectionPosition.initModel(sequelize)
Topic.initModel(sequelize)
Student.belongsToMany(CourseSection, {
as: 'courseSections',
through: CourseSectionEnrollment,
foreignKey: 'student_id',
otherKey: 'course_section_id',
onDelete: 'CASCADE'
})
Teacher.belongsToMany(CourseSection, {
as: 'courseSections',
through: CourseSectionPosition,
foreignKey: 'teacher_id',
otherKey: 'course_section_id',
onDelete: 'CASCADE'
})
Teacher.hasMany(CourseSectionPosition, {
as: 'courseSectionPositions',
foreignKey: 'teacher_id'
})
Course.hasMany(CourseSection, {
as: 'sections',
foreignKey: 'course_id'
})
Course.belongsToMany(Topic, {
as: 'topics',
through: 'course_topics',
foreignKey: 'course_id',
otherKey: 'topic_id',
onDelete: 'CASCADE'
})
CourseSection.belongsTo(Course, {
as: 'course',
foreignKey: 'course_id'
})
CourseSection.belongsToMany(Student, {
as: 'students',
through: CourseSectionEnrollment,
foreignKey: 'course_section_id',
otherKey: 'student_id',
onDelete: 'CASCADE'
})
CourseSection.belongsToMany(Teacher, {
as: 'teachers',
through: CourseSectionPosition,
foreignKey: 'course_section_id',
otherKey: 'teacher_id',
onDelete: 'CASCADE'
})
CourseSectionEnrollment.belongsTo(CourseSection, {
as: 'courseSection',
foreignKey: 'course_section_id'
})
CourseSectionEnrollment.belongsTo(Student, {
as: 'student',
foreignKey: 'student_id'
})
CourseSectionPosition.belongsTo(CourseSection, {
as: 'courseSection',
foreignKey: 'course_section_id'
})
CourseSectionPosition.belongsTo(Teacher, {
as: 'teacher',
foreignKey: 'teacher_id'
})
return {
Student,
Teacher,
Course,
CourseSection,
CourseSectionEnrollment,
CourseSectionPosition,
Topic
}
}