mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-05 21:49:25 +08:00
fix: sync event in inherited collection (#5477)
* fix: sync event in inherited collection * fix: hooks options
This commit is contained in:
parent
063ebd9d05
commit
f3ef42968e
@ -84,6 +84,35 @@ describe.runIf(isPg())('collection inherits', () => {
|
|||||||
expect(err).toBeUndefined();
|
expect(err).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should emit afterSync event', async () => {
|
||||||
|
const Root = db.collection({
|
||||||
|
name: 'root',
|
||||||
|
fields: [
|
||||||
|
{ name: 'name', type: 'string' },
|
||||||
|
{
|
||||||
|
name: 'bs',
|
||||||
|
type: 'hasMany',
|
||||||
|
target: 'b',
|
||||||
|
foreignKey: 'root_id',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const Child = db.collection({
|
||||||
|
name: 'child',
|
||||||
|
inherits: ['root'],
|
||||||
|
});
|
||||||
|
|
||||||
|
const fn = vi.fn();
|
||||||
|
db.on('child.afterSync', (options) => {
|
||||||
|
fn();
|
||||||
|
});
|
||||||
|
|
||||||
|
await db.sync();
|
||||||
|
|
||||||
|
expect(fn).toBeCalled();
|
||||||
|
});
|
||||||
|
|
||||||
it('should append __collection with eager load', async () => {
|
it('should append __collection with eager load', async () => {
|
||||||
const Root = db.collection({
|
const Root = db.collection({
|
||||||
name: 'root',
|
name: 'root',
|
||||||
|
@ -13,6 +13,7 @@ import lodash from 'lodash';
|
|||||||
export class InheritedSyncRunner {
|
export class InheritedSyncRunner {
|
||||||
static async syncInheritModel(model: any, options: any) {
|
static async syncInheritModel(model: any, options: any) {
|
||||||
const { transaction } = options;
|
const { transaction } = options;
|
||||||
|
options.hooks = options.hooks === undefined ? true : !!options.hooks;
|
||||||
|
|
||||||
const inheritedCollection = model.collection as InheritedCollection;
|
const inheritedCollection = model.collection as InheritedCollection;
|
||||||
const db = inheritedCollection.context.database;
|
const db = inheritedCollection.context.database;
|
||||||
@ -153,6 +154,14 @@ export class InheritedSyncRunner {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options.hooks) {
|
||||||
|
await model.runHooks('afterSync', {
|
||||||
|
...options,
|
||||||
|
modelName: model.name,
|
||||||
|
transaction,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async createTable(tableName, attributes, options, model, parents) {
|
static async createTable(tableName, attributes, options, model, parents) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user