mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-22 08:16:09 +08:00
[local-sync, iso-core]: Cascade deletes on hasMany
associations
Summary: Delete associated children when a parent is deleted to prevent foreign key constraint errors. Also make sure any child hooks are run. Test Plan: tested locally Reviewers: evan Reviewed By: evan Differential Revision: https://phab.nylas.com/D3620
This commit is contained in:
parent
aaf0b04ae3
commit
2ed1a03d34
|
@ -28,7 +28,7 @@ module.exports = (sequelize, Sequelize) => {
|
|||
],
|
||||
classMethods: {
|
||||
associate(data = {}) {
|
||||
Account.hasMany(data.AccountToken, {as: 'tokens'})
|
||||
Account.hasMany(data.AccountToken, {as: 'tokens', onDelete: 'cascade', hooks: true})
|
||||
},
|
||||
upsertWithCredentials(accountParams, credentials) {
|
||||
if (!accountParams || !credentials || !accountParams.emailAddress) {
|
||||
|
|
|
@ -40,7 +40,7 @@ module.exports = (sequelize, Sequelize) => {
|
|||
}, {
|
||||
classMethods: {
|
||||
associate({Folder, Message, Thread}) {
|
||||
Folder.hasMany(Message)
|
||||
Folder.hasMany(Message, {onDelete: 'cascade', hooks: true})
|
||||
Folder.belongsToMany(Thread, {through: 'thread_folders'})
|
||||
},
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ module.exports = (sequelize, Sequelize) => {
|
|||
Message.belongsTo(Thread)
|
||||
Message.belongsTo(Folder)
|
||||
Message.belongsToMany(Label, {through: MessageLabel})
|
||||
Message.hasMany(File)
|
||||
Message.hasMany(File, {onDelete: 'cascade', hooks: true})
|
||||
},
|
||||
|
||||
hash({from = [], to = [], cc = [], bcc = [], date = '', subject = '', headerMessageId = ''} = {}) {
|
||||
|
|
|
@ -42,7 +42,7 @@ module.exports = (sequelize, Sequelize) => {
|
|||
associate: ({Thread, Folder, ThreadFolder, Label, ThreadLabel, Message}) => {
|
||||
Thread.belongsToMany(Folder, {through: ThreadFolder})
|
||||
Thread.belongsToMany(Label, {through: ThreadLabel})
|
||||
Thread.hasMany(Message)
|
||||
Thread.hasMany(Message, {onDelete: 'cascade', hooks: true})
|
||||
},
|
||||
},
|
||||
instanceMethods: {
|
||||
|
|
Loading…
Reference in a new issue