From 6e4e6233035dec681f26664a1a36e7acc906bdc2 Mon Sep 17 00:00:00 2001 From: Charles Bochet Date: Thu, 7 Aug 2025 09:49:58 +0200 Subject: [PATCH] Fix update many behavior with composite and connect (#13712) We had two mistakes in updateMany orm behavior: - format of manyInput should be done earlier - relation connect/disconnect does not support batching and should be computed for each input at last moment --- .../workspace-update-query-builder.ts | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/packages/twenty-server/src/engine/twenty-orm/repository/workspace-update-query-builder.ts b/packages/twenty-server/src/engine/twenty-orm/repository/workspace-update-query-builder.ts index 96710abccb..eecee5f874 100644 --- a/packages/twenty-server/src/engine/twenty-orm/repository/workspace-update-query-builder.ts +++ b/packages/twenty-server/src/engine/twenty-orm/repository/workspace-update-query-builder.ts @@ -236,10 +236,7 @@ export class WorkspaceUpdateQueryBuilder< const results: UpdateResult[] = []; for (const input of this.manyInputs) { - this.expressionMap.valuesSet = formatData( - input.partialEntity, - objectMetadata, - ); + this.expressionMap.valuesSet = input.partialEntity; this.where({ id: input.criteria }); const nestedRelationQueryBuilder = new WorkspaceSelectQueryBuilder( @@ -250,6 +247,12 @@ export class WorkspaceUpdateQueryBuilder< this.authContext, ); + this.relationNestedConfig = + this.relationNestedQueries.prepareNestedRelationQueries( + input.partialEntity as QueryDeepPartialEntityWithNestedRelationFields, + mainAliasTarget, + ); + if (isDefined(this.relationNestedConfig)) { const updatedValues = await this.relationNestedQueries.processRelationNestedQueries({ @@ -388,14 +391,15 @@ export class WorkspaceUpdateQueryBuilder< ): this { const mainAliasTarget = this.getMainAliasTarget(); - this.relationNestedConfig = - this.relationNestedQueries.prepareNestedRelationQueries( - inputs.map( - (input) => input.partialEntity, - ) as QueryDeepPartialEntityWithNestedRelationFields[], - mainAliasTarget, - ); - this.manyInputs = inputs; + const objectMetadata = getObjectMetadataFromEntityTarget( + mainAliasTarget, + this.internalContext, + ); + + this.manyInputs = inputs.map((input) => ({ + criteria: input.criteria, + partialEntity: formatData(input.partialEntity, objectMetadata), + })); return this; }