diff --git a/packages/core/database/src/__tests__/fields/datetime-tz.test.ts b/packages/core/database/src/__tests__/fields/datetime-tz.test.ts index 7e6b7ea57b..789063dae5 100644 --- a/packages/core/database/src/__tests__/fields/datetime-tz.test.ts +++ b/packages/core/database/src/__tests__/fields/datetime-tz.test.ts @@ -133,6 +133,49 @@ describe('date-field', () => { await db.close(); }); + it('should set default value if collection is middle table in belongs to many association', async () => { + const middleTable = db.collection({ + name: 'test_middle', + fields: [{ name: 'date1', type: 'datetimeTz', defaultToCurrentTime: true, allowNull: false }], + }); + + const sourceTable = db.collection({ + name: 'test_source', + fields: [ + { + name: 'name', + type: 'string', + }, + { + name: 'target', + target: 'test_target', + type: 'belongsToMany', + through: 'test_middle', + }, + ], + }); + + const targetTable = db.collection({ + name: 'test_target', + fields: [ + { name: 'name', type: 'string' }, + { name: 'source', target: 'test_source', type: 'belongsToMany', through: 'test_middle' }, + ], + }); + + await db.sync(); + + const sourceInstance = await sourceTable.repository.create({ values: { name: 'source' } }); + const targetInstance = await targetTable.repository.create({ values: { name: 'target' } }); + + await sourceTable.repository.update({ + values: { + target: [targetInstance.get('id')], + }, + filter: { id: sourceInstance.get('id') }, + }); + }); + it('should set default to current time', async () => { const c1 = db.collection({ name: 'test11', diff --git a/packages/core/database/src/update-associations.ts b/packages/core/database/src/update-associations.ts index 212ac8f3c3..a0a57f5ecb 100644 --- a/packages/core/database/src/update-associations.ts +++ b/packages/core/database/src/update-associations.ts @@ -421,7 +421,7 @@ export async function updateMultipleAssociation( const createAccessor = association.accessors.create; if (isUndefinedOrNull(value)) { - await model[setAccessor](null, { transaction, context, individualHooks: true }); + await model[setAccessor](null, { transaction, context, individualHooks: true, validate: false }); model.setDataValue(key, null); return; } @@ -433,7 +433,7 @@ export async function updateMultipleAssociation( } if (isStringOrNumber(value)) { - await model[setAccessor](value, { transaction, context, individualHooks: true }); + await model[setAccessor](value, { transaction, context, individualHooks: true, validate: false }); return; } @@ -472,7 +472,7 @@ export async function updateMultipleAssociation( } // associate targets in lists1 - await model[setAccessor](setItems, { transaction, context, individualHooks: true }); + await model[setAccessor](setItems, { transaction, context, individualHooks: true, validate: false }); const newItems = [];