Built motion from commit 7afcba0.|0.0.74
[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   }, {
18     tableName: 'cm_lists',
19     associate: function(models) {
20       List.belongsToMany(models.User, {
21         through: models.UserHasList,
22         foreignKey: 'list'
23       });
24       List.hasMany(models.CustomField, {
25         as: 'CustomFields',
26         required: false
27       });
28       List.hasMany(models.Contact, {
29         as: 'Contacts',
30         onDelete: 'cascade'
31       });
32       List.addScope('customFields', {
33         include: [{
34           model: models.CustomField,
35           as: 'CustomFields'
36         }]
37       });
38     }
39   });
40
41   return List;
42 };