module.exports = function(sequelize, DataTypes) { const project_audio_tracks = sequelize.define( 'project_audio_tracks', { id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true, }, environment: { type: DataTypes.ENUM, values: [ "dev", "stage", "production" ], }, source_key: { type: DataTypes.TEXT, }, name: { type: DataTypes.TEXT, }, slug: { type: DataTypes.TEXT, }, url: { type: DataTypes.TEXT, }, loop: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, }, volume: { type: DataTypes.DECIMAL, }, sort_order: { type: DataTypes.INTEGER, }, is_enabled: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false, }, importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true, }, }, { timestamps: true, paranoid: true, freezeTableName: true, }, ); project_audio_tracks.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.project_audio_tracks.belongsTo(db.projects, { as: 'project', foreignKey: { name: 'projectId', }, constraints: false, }); db.project_audio_tracks.belongsTo(db.users, { as: 'createdBy', }); db.project_audio_tracks.belongsTo(db.users, { as: 'updatedBy', }); }; return project_audio_tracks; };