diff --git a/packages/core/database/src/__tests__/update-associations-through.test.ts b/packages/core/database/src/__tests__/update-associations-through.test.ts index 097ff1c0a..2e926bb3f 100644 --- a/packages/core/database/src/__tests__/update-associations-through.test.ts +++ b/packages/core/database/src/__tests__/update-associations-through.test.ts @@ -22,7 +22,7 @@ describe('update through', () => { type: 'integer', primaryKey: true, autoIncrement: true, - } + }, ], }); db.collection({ @@ -45,6 +45,10 @@ describe('update through', () => { fields: [], }); 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({ values: {}, }); @@ -60,7 +64,10 @@ describe('update through', () => { b: [b.toJSON()], }, }); + 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); }); }); diff --git a/packages/core/database/src/update-associations.ts b/packages/core/database/src/update-associations.ts index 7d5e728d3..cd9bd4a86 100644 --- a/packages/core/database/src/update-associations.ts +++ b/packages/core/database/src/update-associations.ts @@ -392,7 +392,7 @@ export async function updateMultipleAssociation( } if (isStringOrNumber(value)) { - await model[setAccessor](value, { transaction, context }); + await model[setAccessor](value, { transaction, context, individualHooks: true }); return; } @@ -424,7 +424,7 @@ export async function updateMultipleAssociation( } // associate targets in lists1 - await model[setAccessor](list1, { transaction, context }); + await model[setAccessor](list1, { transaction, context, individualHooks: true }); const list3 = []; for (const item of list2) {