dfbf050977c1da0df3c03758035a9968c65ff26e
[motion.git] / server / models / cm_list.js
1 /* jshint indent: 2 */
2
3 module.exports = function(sequelize, DataTypes) {
4   var List = sequelize.define('List', {
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     variables: DataTypes.TEXT
18   }, {
19     tableName: 'cm_lists',
20     associate: function(models) {
21       List.belongsToMany(models.User, {
22         through: models.UserHasList,
23         foreignKey: 'list'
24       });
25       List.hasMany(models.CustomField, {
26         as: 'CustomFields',
27         required: false
28       });
29       List.hasMany(models.Contact, {
30         as: 'Contacts',
31         onDelete: 'cascade'
32       });
33       List.addScope('customFields', {
34         include: [{
35           model: models.CustomField,
36           as: 'CustomFields'
37         }]
38       });
39     }
40   });
41
42   return List;
43 };