fix: through collection individual hooks (#1378)

This commit is contained in:
chenos 2023-01-17 12:32:28 +08:00 committed by GitHub
parent 47158e0282
commit d4d8d747b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -22,7 +22,7 @@ describe('update through', () => {
type: 'integer', type: 'integer',
primaryKey: true, primaryKey: true,
autoIncrement: true, autoIncrement: true,
} },
], ],
}); });
db.collection({ db.collection({
@ -45,6 +45,10 @@ describe('update through', () => {
fields: [], fields: [],
}); });
await db.sync(); await db.sync();
const callback1 = jest.fn();
const callback2 = jest.fn();
db.on('c.afterCreate', callback1);
db.on('c.afterBulkCreate', callback2);
const b = await db.getRepository('b').create({ const b = await db.getRepository('b').create({
values: {}, values: {},
}); });
@ -60,7 +64,10 @@ describe('update through', () => {
b: [b.toJSON()], b: [b.toJSON()],
}, },
}); });
const c2 = await db.getRepository('c').findOne(); const c2 = await db.getRepository('c').findOne();
expect(c1.get('id')).toBe(c2.get('id')) expect(c1.get('id')).toBe(c2.get('id'));
expect(callback1).toHaveBeenCalledTimes(1);
expect(callback2).toHaveBeenCalledTimes(1);
}); });
}); });

View File

@ -392,7 +392,7 @@ export async function updateMultipleAssociation(
} }
if (isStringOrNumber(value)) { if (isStringOrNumber(value)) {
await model[setAccessor](value, { transaction, context }); await model[setAccessor](value, { transaction, context, individualHooks: true });
return; return;
} }
@ -424,7 +424,7 @@ export async function updateMultipleAssociation(
} }
// associate targets in lists1 // associate targets in lists1
await model[setAccessor](list1, { transaction, context }); await model[setAccessor](list1, { transaction, context, individualHooks: true });
const list3 = []; const list3 = [];
for (const item of list2) { for (const item of list2) {