288b512d81303178c4ae19f7c06eba9e468f50f1
[motion.git] / server / models / contact.js
1 /**
2  * Contact Model
3  */
4
5 module.exports = function(sequelize, DataTypes) {
6
7   var Contact = sequelize.define('Contact', {
8     fullname: {
9       type: DataTypes.STRING,
10       validate: {
11         notEmpty: true
12       }
13     },
14     tags: DataTypes.STRING,
15     // CompanyId: DataTypes.STRING,/Da creare con l' associazione
16     street: DataTypes.STRING,
17     postalCode: DataTypes.STRING,
18     city: DataTypes.STRING,
19     country: DataTypes.STRING,
20     dateOfBirth: DataTypes.STRING,
21     description: DataTypes.STRING
22   }, {
23     tableName: 'contacts',
24     associate: function(models) {
25       Contact.belongsToMany(models.ContactPhone, {
26         through: 'contact_has_phones',
27         as: 'Phones'
28       });
29       Contact.belongsToMany(models.ContactEmail, {
30         through: 'contact_has_emails',
31         as: 'Emails'
32       });
33       Contact.belongsToMany(models.CustomField, {
34         through: models.ContactHasCustomField,
35         as: 'CustomFields'
36       });
37       Contact.belongsTo(models.Company);
38       Contact.belongsTo(models.User);
39     }
40   });
41
42   return Contact;
43 };