const config = require('../../config'); const providers = config.providers; const crypto = require('crypto'); const bcrypt = require('bcrypt'); const moment = require('moment'); module.exports = function(sequelize, DataTypes) { const class_groups = sequelize.define( 'class_groups', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, class_name: { type: DataTypes.TEXT, }, grade_level: { type: DataTypes.TEXT, }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); class_groups.associate = (db) => { /// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity db.class_groups.hasMany(db.enrollments, { as: 'enrollments_class_group', foreignKey: { name: 'class_groupId', }, constraints: false, }); db.class_groups.hasMany(db.teacher_assignments, { as: 'teacher_assignments_class_group', foreignKey: { name: 'class_groupId', }, constraints: false, }); db.class_groups.hasMany(db.exams, { as: 'exams_class_group', foreignKey: { name: 'class_groupId', }, constraints: false, }); //end loop db.class_groups.belongsTo(db.schools, { as: 'school', foreignKey: { name: 'schoolId', }, constraints: false, }); db.class_groups.belongsTo(db.academic_years, { as: 'academic_year', foreignKey: { name: 'academic_yearId', }, constraints: false, }); db.class_groups.belongsTo(db.users, { as: 'homeroom_teacher', foreignKey: { name: 'homeroom_teacherId', }, constraints: false, }); db.class_groups.belongsTo(db.users, { as: 'createdBy', }); db.class_groups.belongsTo(db.users, { as: 'updatedBy', }); }; return class_groups; };