fix: destroy collection fields (#536)

This commit is contained in:
chenos 2022-06-25 10:36:56 +08:00 committed by GitHub
parent ef939b4277
commit 9dae723ca7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -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

View File

@ -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);
});