summaryrefslogblamecommitdiffstats
path: root/server/models/group.js
blob: 472ecf24616bc2a022e86eba24ed7c969c247538 (plain) (tree)
1
2
3
4
5
6
7
8
9








                                            
                           
                                       


                     
                                       
                                                                                                         



                                                                                                                             
                                  


              
'use strict'
module.exports = (sequelize, DataTypes) => {
  var group = sequelize.define('group', {
    id: {
      allowNull: false,
      autoIncrement: true,
      primaryKey: true,
      type: DataTypes.INTEGER
    },
    name: DataTypes.STRING,
    description: DataTypes.STRING(2048)
  }, {
    timestamps: false
  })
  group.associate = function (models) {
    var GroupXGroup = sequelize.define('group_x_group', {}, { timestamps: false, freezeTableName: true })
    var GroupXClient = sequelize.define('group_x_client', {}, { timestamps: false, freezeTableName: true })
    group.belongsToMany(group, { as: 'parents', through: GroupXGroup, foreignKey: 'childId', otherKey: 'parentId' })
    group.belongsToMany(group, { as: 'subgroups', through: GroupXGroup, foreignKey: 'parentId', otherKey: 'childId' })
    group.belongsToMany(models.client, { as: 'clients', through: GroupXClient, foreignKey: 'groupId', otherKey: 'clientId' })
    group.belongsTo(models.config)
  }
  return group
}