2017-03-14 01:02:43 -04:00
|
|
|
'use strict'
|
2016-07-29 23:21:38 -04:00
|
|
|
// external modules
|
2017-03-08 05:45:51 -05:00
|
|
|
var Sequelize = require('sequelize')
|
2016-07-29 23:21:38 -04:00
|
|
|
|
|
|
|
module.exports = function (sequelize, DataTypes) {
|
2017-03-08 05:45:51 -05:00
|
|
|
var Author = sequelize.define('Author', {
|
|
|
|
id: {
|
|
|
|
type: Sequelize.INTEGER,
|
|
|
|
primaryKey: true,
|
|
|
|
autoIncrement: true
|
|
|
|
},
|
|
|
|
color: {
|
|
|
|
type: DataTypes.STRING
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
indexes: [
|
|
|
|
{
|
|
|
|
unique: true,
|
|
|
|
fields: ['noteId', 'userId']
|
|
|
|
}
|
2019-04-12 00:05:32 -04:00
|
|
|
]
|
2017-03-08 05:45:51 -05:00
|
|
|
})
|
2019-04-12 00:05:32 -04:00
|
|
|
|
|
|
|
Author.associate = function (models) {
|
|
|
|
Author.belongsTo(models.Note, {
|
|
|
|
foreignKey: 'noteId',
|
|
|
|
as: 'note',
|
|
|
|
constraints: false,
|
|
|
|
onDelete: 'CASCADE',
|
|
|
|
hooks: true
|
|
|
|
})
|
|
|
|
Author.belongsTo(models.User, {
|
|
|
|
foreignKey: 'userId',
|
|
|
|
as: 'user',
|
|
|
|
constraints: false,
|
|
|
|
onDelete: 'CASCADE',
|
|
|
|
hooks: true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-03-08 05:45:51 -05:00
|
|
|
return Author
|
|
|
|
}
|