Merge branch 'main' into next

This commit is contained in:
nocobase[bot] 2024-10-22 05:43:44 +00:00
commit cb336ed4d9
2 changed files with 48 additions and 10 deletions

View File

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

View File

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