28 lines
769 B
JavaScript
28 lines
769 B
JavaScript
|
|
module.exports = function (sequelize, DataTypes) {
|
||
|
|
const Entity = sequelize.define('Entity', {
|
||
|
|
id: {
|
||
|
|
type: DataTypes.UUID,
|
||
|
|
defaultValue: DataTypes.UUIDV4,
|
||
|
|
primaryKey: true,
|
||
|
|
},
|
||
|
|
name: {
|
||
|
|
type: DataTypes.STRING,
|
||
|
|
allowNull: false
|
||
|
|
},
|
||
|
|
}, {
|
||
|
|
tableName: 'entities',
|
||
|
|
freezeTableName: true,
|
||
|
|
timestamps: true,
|
||
|
|
});
|
||
|
|
|
||
|
|
Entity.associate = function (models) {
|
||
|
|
Entity.EntityTypes = Entity.belongsToMany(models.EntityType, {
|
||
|
|
through: models.EntityEntitiesTypes,
|
||
|
|
foreignKey: 'entityId'
|
||
|
|
});
|
||
|
|
Entity.Users = Entity.hasMany(models.User, {
|
||
|
|
foreignKey: 'entityId'
|
||
|
|
});
|
||
|
|
};
|
||
|
|
return Entity;
|
||
|
|
};
|