Built motion from commit 95b01fa.|0.0.70
[motion.git] / server / models / service.js
1 /* jshint indent: 2 */
2
3 module.exports = function(sequelize, DataTypes) {
4   var Service = sequelize.define('Service', {
5     name: {
6       type: DataTypes.STRING,
7       unique: true
8     },
9     description: {
10       type: DataTypes.STRING,
11       allowNull: true,
12     },
13     defaultEntry: {
14       type: DataTypes.BOOLEAN,
15       defaultValue: false
16     }
17   }, {
18     tableName: 'services',
19     associate: function(models) {
20       Service.belongsToMany(models.User, {
21         through: models.UserHasService,
22         foreignKey: 'service'
23       });
24       Service.hasMany(models.CustomField, {
25         as: 'CustomFields',
26         required: false
27       });
28       Service.hasMany(models.Contact, {
29         as: 'Contacts',
30         onDelete: 'cascade'
31       });
32       Service.addScope('customFields', {
33         include: [{
34           model: models.CustomField,
35           as: 'CustomFields'
36         }]
37       });
38     }
39   });
40
41   return Service;
42 };