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 streams = sequelize.define( 'streams', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, url: { type: DataTypes.TEXT, }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); streams.associate = (db) => { db.streams.belongsToMany(db.ads, { as: 'ads', foreignKey: { name: 'streams_adsId', }, constraints: false, through: 'streamsAdsAds', }); db.streams.belongsToMany(db.ads, { as: 'ads_filter', foreignKey: { name: 'streams_adsId', }, constraints: false, through: 'streamsAdsAds', }); /// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity //end loop db.streams.belongsTo(db.matches, { as: 'match', foreignKey: { name: 'matchId', }, constraints: false, }); db.streams.belongsTo(db.users, { as: 'createdBy', }); db.streams.belongsTo(db.users, { as: 'updatedBy', }); }; return streams; };