mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 07:25:15 +00:00
Merge branch 'main' into next
This commit is contained in:
commit
cb336ed4d9
@ -84,6 +84,35 @@ describe.runIf(isPg())('collection inherits', () => {
|
||||
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 () => {
|
||||
const Root = db.collection({
|
||||
name: 'root',
|
||||
|
@ -13,6 +13,7 @@ import lodash from 'lodash';
|
||||
export class InheritedSyncRunner {
|
||||
static async syncInheritModel(model: any, options: any) {
|
||||
const { transaction } = options;
|
||||
options.hooks = options.hooks === undefined ? true : !!options.hooks;
|
||||
|
||||
const inheritedCollection = model.collection as InheritedCollection;
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user