mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 07:25:15 +00:00
feat(database): add afterUpdateAssociations hook
This commit is contained in:
parent
fe8476c5dd
commit
93d8426c84
@ -264,7 +264,7 @@ export default class Database {
|
||||
* @param hookType
|
||||
* @param fn
|
||||
*/
|
||||
public addHook(hookType: HookType, fn: Function) {
|
||||
public addHook(hookType: HookType | string, fn: Function) {
|
||||
const hooks = this.hooks[hookType] || [];
|
||||
hooks.push(fn);
|
||||
this.hooks[hookType] = hooks;
|
||||
@ -276,11 +276,11 @@ export default class Database {
|
||||
* @param hookType
|
||||
* @param args
|
||||
*/
|
||||
public runHooks(hookType: HookType, ...args) {
|
||||
public async runHooks(hookType: HookType | string, ...args) {
|
||||
const hooks = this.hooks[hookType] || [];
|
||||
for (const hook of hooks) {
|
||||
if (typeof hook === 'function') {
|
||||
hook(...args);
|
||||
await hook(...args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -511,6 +511,13 @@ export abstract class Model extends SequelizeModel {
|
||||
});
|
||||
}
|
||||
|
||||
await this.database.runHooks('afterUpdateAssociations', this, {
|
||||
...options,
|
||||
transaction,
|
||||
});
|
||||
// @ts-ignore
|
||||
// await this.sequelize.runHooks('afterUpdateAssociations', this, options);
|
||||
|
||||
if (!options.transaction) {
|
||||
await transaction.commit();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user