hedgedoc/lib/models/author.js
Sheogorath 408ab7ae1d
Use cascaded deletes
When we delete a user we should delete all the notes that belong to this
user including the revisions of these notes.

Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
2018-05-25 14:55:18 +02:00

42 lines
886 B
JavaScript

'use strict'
// 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,
onDelete: 'CASCADE',
hooks: true
})
Author.belongsTo(models.User, {
foreignKey: 'userId',
as: 'user',
constraints: false,
onDelete: 'CASCADE',
hooks: true
})
}
}
})
return Author
}