Skip to content

Commit 408ab7a

Browse files
committed
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>
1 parent 8aa5c03 commit 408ab7a

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

lib/models/author.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ module.exports = function (sequelize, DataTypes) {
2424
Author.belongsTo(models.Note, {
2525
foreignKey: 'noteId',
2626
as: 'note',
27-
constraints: false
27+
constraints: false,
28+
onDelete: 'CASCADE',
29+
hooks: true
2830
})
2931
Author.belongsTo(models.User, {
3032
foreignKey: 'userId',
3133
as: 'user',
32-
constraints: false
34+
constraints: false,
35+
onDelete: 'CASCADE',
36+
hooks: true
3337
})
3438
}
3539
}

lib/models/note.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ module.exports = function (sequelize, DataTypes) {
9191
Note.belongsTo(models.User, {
9292
foreignKey: 'ownerId',
9393
as: 'owner',
94-
constraints: false
94+
constraints: false,
95+
onDelete: 'CASCADE',
96+
hooks: true
9597
})
9698
Note.belongsTo(models.User, {
9799
foreignKey: 'lastchangeuserId',

lib/models/revision.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ module.exports = function (sequelize, DataTypes) {
102102
Revision.belongsTo(models.Note, {
103103
foreignKey: 'noteId',
104104
as: 'note',
105-
constraints: false
105+
constraints: false,
106+
onDelete: 'CASCADE',
107+
hooks: true
106108
})
107109
},
108110
getNoteRevisions: function (note, callback) {

0 commit comments

Comments
 (0)