2017-03-14 01:02:43 -04:00
|
|
|
'use strict'
|
2016-07-29 23:21:38 -04:00
|
|
|
// external modules
|
2021-02-15 03:42:51 -05:00
|
|
|
const Sequelize = require('sequelize')
|
2016-07-29 23:21:38 -04:00
|
|
|
|
|
|
|
module.exports = function (sequelize, DataTypes) {
|
2021-02-15 03:42:51 -05:00
|
|
|
const Author = sequelize.define('Author', {
|
2017-03-08 05:45:51 -05:00
|
|
|
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
|
|
|
|
}
|