9454f31ba3957544dcc5a6dc7a5efa5ffae5c88d
[motion.git] / server / models / tools_tag.js
1 /**
2  * tag Model
3  */
4
5 module.exports = function(sequelize, DataTypes) {
6
7   var Tag = sequelize.define('Tag', {
8     name: {
9       type: DataTypes.STRING,
10       unique: true,
11       allowNull: false,
12       validate: {
13         notEmpty: true,
14         is: /[A-Za-z0-9._\\+*!-]+/
15       }
16     },
17     description: DataTypes.STRING
18   }, {
19     tableName: 'tools_tags',
20     associate: function(models) {
21       Tag.belongsToMany(models.ZendeskConfiguration, {
22         through: 'zendesk_configuration_has_tags'
23       });
24       Tag.belongsToMany(models.FreshdeskConfiguration, {
25         through: 'int_freshdesk_configuration_has_tags'
26       });
27       Tag.addScope('configuration', {
28         include: [{
29           all: true
30         }]
31       });
32     }
33   });
34
35   return Tag;
36 };