summaryrefslogtreecommitdiff
path: root/lib/models/author.js
blob: 0b0f149d967d40773033aad76fa61c61be14d501 (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
38
39
40
41
42
43
"use strict";

// external modules
var Sequelize = require("sequelize");

// core
var logger = require("../logger.js");

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;
};