08d704f8e57050fda7d1440c36bde9cc6c7fe17d
[motion.git] / server / models / contact_phone.js
1 /**
2  * Contact Model
3  */
4
5 module.exports = function (sequelize, DataTypes) {
6
7   var ContactPhone = sequelize.define('ContactPhone', {
8     phone: {
9       type: DataTypes.STRING,
10       primaryKey: true
11     }
12   }, {
13     tableName: 'contact_phones',
14     associate: function (models) {
15       ContactPhone.belongsToMany(models.Contact, {
16         through: 'contact_has_phones'
17       });
18       ContactPhone.hasMany(models.ReportCall, {
19         as: 'Inbounds',
20         foreignKey: 'source',
21         constraints: false
22       });
23       ContactPhone.hasMany(models.ReportCall, {
24         as: 'Outbounds',
25         foreignKey: 'destination',
26         constraints: false
27       });
28     }
29   });
30
31   return ContactPhone;
32 };