summaryrefslogtreecommitdiff
path: root/lib/models/author.js
blob: 5e39c3478aa76b4663102b12208225d60bcd9c30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// external modules
var Sequelize = require('sequelize')

module.exports = function (sequelize, DataTypes) {
  var Author = sequelize.define('Author', {
    id: {
      type: Sequelize.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    color: {
      type: DataTypes.STRING
    }
  }, {
    indexes: [
      {
        unique: true,
        fields: ['noteId', 'userId']
      }
    ],
    classMethods: {
      associate: function (models) {
        Author.belongsTo(models.Note, {
          foreignKey: 'noteId',
          as: 'note',
          constraints: false
        })
        Author.belongsTo(models.User, {
          foreignKey: 'userId',
          as: 'user',
          constraints: false
        })
      }
    }
  })
  return Author
}