From 9dae723ca7f0c5ff9103b5502a6823f46a3bc083 Mon Sep 17 00:00:00 2001 From: chenos Date: Sat, 25 Jun 2022 10:36:56 +0800 Subject: [PATCH] fix: destroy collection fields (#536) --- packages/core/database/src/fields/field.ts | 6 ++++++ packages/plugins/collection-manager/src/server.ts | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/core/database/src/fields/field.ts b/packages/core/database/src/fields/field.ts index 2d3498668..de4fca9fd 100644 --- a/packages/core/database/src/fields/field.ts +++ b/packages/core/database/src/fields/field.ts @@ -145,6 +145,12 @@ export abstract class Field { let sql; if (this.database.sequelize.getDialect() === 'sqlite') { sql = `SELECT * from pragma_table_info('${this.collection.model.tableName}') WHERE name = '${this.name}'`; + } else if (this.database.inDialect('mysql')) { + sql = ` + select column_name + from INFORMATION_SCHEMA.COLUMNS + where TABLE_SCHEMA='${this.database.options.database}' AND TABLE_NAME='${this.collection.model.tableName}' AND column_name='${this.name}' + `; } else { sql = ` select column_name diff --git a/packages/plugins/collection-manager/src/server.ts b/packages/plugins/collection-manager/src/server.ts index 33ff5156c..d29277b16 100644 --- a/packages/plugins/collection-manager/src/server.ts +++ b/packages/plugins/collection-manager/src/server.ts @@ -77,11 +77,11 @@ export class CollectionManagerPlugin extends Plugin { } }); - this.app.db.on('fields.afterDestroy', async (model, options) => { + this.app.db.on('fields.beforeDestroy', async (model, options) => { await model.remove(options); }); - this.app.db.on('collections.afterDestroy', async (model, options) => { + this.app.db.on('collections.beforeDestroy', async (model, options) => { await model.remove(options); });