Skip to content

The open alternative to Salesforce, designed for AI.

Fix update many behavior with composite and connect (#13712)

Charles Bochet6e4e6233035d
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 96710abccb4..eecee5f8748 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<T>,
+ 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<T>[],
- 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;
}