5 module.exports = function(sequelize, DataTypes) {
7 var Contact = sequelize.define('Contact', {
9 type: DataTypes.STRING,
14 lastName: DataTypes.STRING,
16 type: DataTypes.STRING,
19 if (this.getDataValue('tags')) {
20 tags = this.getDataValue('tags').split(';');
21 if (tags.length > 1) {
24 tags = []; //if the length is 1 the value is still in the format of the old tags, with comma separator. So I return an empty array since the old format is obsolete and invalid
32 this.setDataValue('tags', val && val.length ? val.join(';') + ';' : null);
35 street: DataTypes.STRING,
36 postalCode: DataTypes.STRING,
37 city: DataTypes.STRING,
38 country: DataTypes.STRING,
39 dateOfBirth: DataTypes.STRING,
40 description: DataTypes.TEXT,
41 phone: DataTypes.STRING,
42 mobile: DataTypes.STRING,
43 fax: DataTypes.STRING,
44 email: DataTypes.STRING,
47 tableName: 'cm_contacts',
48 associate: function(models) {
49 Contact.belongsTo(models.Company);
50 Contact.belongsTo(models.User);
51 Contact.belongsTo(models.List);
52 Contact.addScope('list', {
53 include: [models.List]
55 Contact.addScope('company', {
56 include: [models.Company]
58 Contact.addScope('user', {
59 include: [models.User]
61 Contact.addScope('company_list_filter', function(query) {
65 if (query.CompanyId) {
66 scope.where.CompanyId = query.CompanyId;
69 scope.where.ListId = query.ListId;