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>
This commit is contained in:
Sheogorath 2018-05-25 14:54:00 +02:00
parent 8aa5c03213
commit 408ab7ae1d
No known key found for this signature in database
GPG key ID: 1F05CC3635CDDFFD
3 changed files with 12 additions and 4 deletions

View file

@ -24,12 +24,16 @@ module.exports = function (sequelize, DataTypes) {
Author.belongsTo(models.Note, {
foreignKey: 'noteId',
as: 'note',
constraints: false
constraints: false,
onDelete: 'CASCADE',
hooks: true
})
Author.belongsTo(models.User, {
foreignKey: 'userId',
as: 'user',
constraints: false
constraints: false,
onDelete: 'CASCADE',
hooks: true
})
}
}

View file

@ -91,7 +91,9 @@ module.exports = function (sequelize, DataTypes) {
Note.belongsTo(models.User, {
foreignKey: 'ownerId',
as: 'owner',
constraints: false
constraints: false,
onDelete: 'CASCADE',
hooks: true
})
Note.belongsTo(models.User, {
foreignKey: 'lastchangeuserId',

View file

@ -102,7 +102,9 @@ module.exports = function (sequelize, DataTypes) {
Revision.belongsTo(models.Note, {
foreignKey: 'noteId',
as: 'note',
constraints: false
constraints: false,
onDelete: 'CASCADE',
hooks: true
})
},
getNoteRevisions: function (note, callback) {