mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 11:16:31 -05:00
136d895d15
Signed-off-by: Philip Molares <philip.molares@udo.edu>
42 lines
809 B
JavaScript
42 lines
809 B
JavaScript
'use strict'
|
|
// external modules
|
|
const Sequelize = require('sequelize')
|
|
|
|
module.exports = function (sequelize, DataTypes) {
|
|
const Author = sequelize.define('Author', {
|
|
id: {
|
|
type: Sequelize.INTEGER,
|
|
primaryKey: true,
|
|
autoIncrement: true
|
|
},
|
|
color: {
|
|
type: DataTypes.STRING
|
|
}
|
|
}, {
|
|
indexes: [
|
|
{
|
|
unique: true,
|
|
fields: ['noteId', 'userId']
|
|
}
|
|
]
|
|
})
|
|
|
|
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
|
|
})
|
|
}
|
|
|
|
return Author
|
|
}
|