mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 07:57:20 +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 hookType
|
||||||
* @param fn
|
* @param fn
|
||||||
*/
|
*/
|
||||||
public addHook(hookType: HookType, fn: Function) {
|
public addHook(hookType: HookType | string, fn: Function) {
|
||||||
const hooks = this.hooks[hookType] || [];
|
const hooks = this.hooks[hookType] || [];
|
||||||
hooks.push(fn);
|
hooks.push(fn);
|
||||||
this.hooks[hookType] = hooks;
|
this.hooks[hookType] = hooks;
|
||||||
@ -276,11 +276,11 @@ export default class Database {
|
|||||||
* @param hookType
|
* @param hookType
|
||||||
* @param args
|
* @param args
|
||||||
*/
|
*/
|
||||||
public runHooks(hookType: HookType, ...args) {
|
public async runHooks(hookType: HookType | string, ...args) {
|
||||||
const hooks = this.hooks[hookType] || [];
|
const hooks = this.hooks[hookType] || [];
|
||||||
for (const hook of hooks) {
|
for (const hook of hooks) {
|
||||||
if (typeof hook === 'function') {
|
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) {
|
if (!options.transaction) {
|
||||||
await transaction.commit();
|
await transaction.commit();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user