mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 13:46:45 +00:00
fix: missing transaction (#531)
This commit is contained in:
parent
33a08288c0
commit
245bd01bd6
@ -0,0 +1,33 @@
|
||||
import { mockDatabase } from '../';
|
||||
import { Database } from '../../database';
|
||||
|
||||
describe('afterCreateWithAssociations', () => {
|
||||
let db: Database;
|
||||
|
||||
beforeEach(async () => {
|
||||
db = mockDatabase();
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await db.close();
|
||||
});
|
||||
|
||||
test('case 1', async () => {
|
||||
db.collection({
|
||||
name: 'test',
|
||||
});
|
||||
await db.sync();
|
||||
const repo = db.getRepository('test');
|
||||
db.on('test.afterCreateWithAssociations', async (model, { transaction }) => {
|
||||
throw new Error('test error');
|
||||
});
|
||||
try {
|
||||
await repo.create({
|
||||
values: {},
|
||||
});
|
||||
} catch (error) {
|
||||
}
|
||||
const count = await repo.count();
|
||||
expect(count).toBe(0);
|
||||
});
|
||||
});
|
@ -165,8 +165,14 @@ export abstract class MultipleRelationRepository extends RelationRepository {
|
||||
|
||||
for (const instance of instances) {
|
||||
if (options.hooks !== false) {
|
||||
await this.db.emitAsync(`${this.targetCollection.name}.afterUpdateWithAssociations`, instance, {...options, transaction});
|
||||
await this.db.emitAsync(`${this.targetCollection.name}.afterSaveWithAssociations`, instance, {...options, transaction});
|
||||
await this.db.emitAsync(`${this.targetCollection.name}.afterUpdateWithAssociations`, instance, {
|
||||
...options,
|
||||
transaction,
|
||||
});
|
||||
await this.db.emitAsync(`${this.targetCollection.name}.afterSaveWithAssociations`, instance, {
|
||||
...options,
|
||||
transaction,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -307,8 +307,14 @@ export class Repository<TModelAttributes extends {} = any, TCreationAttributes e
|
||||
});
|
||||
|
||||
if (options.hooks !== false) {
|
||||
await this.database.emitAsync(`${this.collection.name}.afterCreateWithAssociations`, instance, options);
|
||||
await this.database.emitAsync(`${this.collection.name}.afterSaveWithAssociations`, instance, options);
|
||||
await this.database.emitAsync(`${this.collection.name}.afterCreateWithAssociations`, instance, {
|
||||
...options,
|
||||
transaction,
|
||||
});
|
||||
await this.database.emitAsync(`${this.collection.name}.afterSaveWithAssociations`, instance, {
|
||||
...options,
|
||||
transaction,
|
||||
});
|
||||
}
|
||||
|
||||
return instance;
|
||||
@ -362,8 +368,14 @@ export class Repository<TModelAttributes extends {} = any, TCreationAttributes e
|
||||
|
||||
if (options.hooks !== false) {
|
||||
for (const instance of instances) {
|
||||
await this.database.emitAsync(`${this.collection.name}.afterUpdateWithAssociations`, instance, options);
|
||||
await this.database.emitAsync(`${this.collection.name}.afterSaveWithAssociations`, instance, options);
|
||||
await this.database.emitAsync(`${this.collection.name}.afterUpdateWithAssociations`, instance, {
|
||||
...options,
|
||||
transaction,
|
||||
});
|
||||
await this.database.emitAsync(`${this.collection.name}.afterSaveWithAssociations`, instance, {
|
||||
...options,
|
||||
transaction,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user