summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSheogorath2018-05-25 14:54:00 +0200
committerSheogorath2018-05-25 14:55:18 +0200
commit408ab7ae1dfa5d1c7dedb2f9fde239596520b2e6 (patch)
tree65efa501b128c268497e9bf226a9f1332d8c8e48
parent8aa5c03213fb8809c4d41f95ee6b8d8e2967812a (diff)
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>
Diffstat (limited to '')
-rw-r--r--lib/models/author.js8
-rw-r--r--lib/models/note.js4
-rw-r--r--lib/models/revision.js4
3 files changed, 12 insertions, 4 deletions
diff --git a/lib/models/author.js b/lib/models/author.js
index 8b4f74e5..03f832a4 100644
--- a/lib/models/author.js
+++ b/lib/models/author.js
@@ -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
})
}
}
diff --git a/lib/models/note.js b/lib/models/note.js
index 7b9a909a..7d8e9625 100644
--- a/lib/models/note.js
+++ b/lib/models/note.js
@@ -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',
diff --git a/lib/models/revision.js b/lib/models/revision.js
index 9ecd14dc..8bc95cb1 100644
--- a/lib/models/revision.js
+++ b/lib/models/revision.js
@@ -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) {