'use strict' module.exports = (sequelize, DataTypes) => { var backend = sequelize.define('backend', { id: { allowNull: false, autoIncrement: true, primaryKey: true, type: DataTypes.INTEGER }, name: DataTypes.STRING, type: DataTypes.STRING, credentials: { allowNull: false, type: DataTypes.STRING(2048), defaultValue: '[]' }, groupTypes: { allowNull: false, type: DataTypes.STRING(4096), defaultValue: '[]' }, clientTypes: { allowNull: false, type: DataTypes.STRING(4096), defaultValue: '[]' }, sync: { type: DataTypes.STRING(1024) } }, { timestamps: false }) backend.associate = function (models) { var BackendXGroup = sequelize.define('backend_x_group', { backendId: { type: DataTypes.INTEGER, primaryKey: true }, groupId: { type: DataTypes.INTEGER, primaryKey: false }, externalId: { type: DataTypes.STRING(128), primaryKey: true }, externalType: DataTypes.STRING }, { timestamps: false, freezeTableName: true }) var BackendXClient = sequelize.define('backend_x_client', { backendId: { type: DataTypes.INTEGER, primaryKey: true }, clientId: { type: DataTypes.INTEGER, primaryKey: false }, externalId: { type: DataTypes.STRING(128), primaryKey: true }, externalType: DataTypes.STRING }, { timestamps: false, freezeTableName: true }) backend.belongsToMany(models.group, { as: 'mappedGroups', through: BackendXGroup, foreignKey: 'backendId', otherKey: 'groupId' }) backend.belongsToMany(models.client, { as: 'mappedClients', through: BackendXClient, foreignKey: 'backendId', otherKey: 'clientId' }) backend.hasMany(BackendXGroup, { as: 'groupMappings', foreignKey: 'backendId' }) backend.hasMany(BackendXClient, { as: 'clientMappings', foreignKey: 'backendId' }) } return backend }