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 charts = sequelize.define( 'charts', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, chart_name: { type: DataTypes.TEXT, }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); charts.associate = (db) => { /// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity //end loop db.charts.hasMany(db.file, { as: 'chart_image', foreignKey: 'belongsToId', constraints: false, scope: { belongsTo: db.charts.getTableName(), belongsToColumn: 'chart_image', }, }); db.charts.belongsTo(db.users, { as: 'createdBy', }); db.charts.belongsTo(db.users, { as: 'updatedBy', }); }; return charts; };