The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
UpdateMany - Process connect queries in batch (#13907)
Etienne5eba2a8011ca
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.tsindex 3052ac897ad..c5768dd0061 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@@ -235,37 +235,41 @@ export class WorkspaceUpdateQueryBuilder<const results: UpdateResult[] = [];- for (const input of this.manyInputs) {- this.expressionMap.valuesSet = input.partialEntity;- this.where({ id: input.criteria });+ const nestedRelationQueryBuilder = new WorkspaceSelectQueryBuilder(+ this as unknown as WorkspaceSelectQueryBuilder<T>,+ this.objectRecordsPermissions,+ this.internalContext,+ this.shouldBypassPermissionChecks,+ this.authContext,+ );- const nestedRelationQueryBuilder = new WorkspaceSelectQueryBuilder(- this as unknown as WorkspaceSelectQueryBuilder<T>,- this.objectRecordsPermissions,- this.internalContext,- this.shouldBypassPermissionChecks,- this.authContext,+ this.relationNestedConfig =+ this.relationNestedQueries.prepareNestedRelationQueries(+ this.manyInputs.map(+ (input) => input.partialEntity,+ ) as QueryDeepPartialEntityWithNestedRelationFields<T>[],+ mainAliasTarget,);- this.relationNestedConfig =- this.relationNestedQueries.prepareNestedRelationQueries(- input.partialEntity as QueryDeepPartialEntityWithNestedRelationFields<T>,- mainAliasTarget,- );-- if (isDefined(this.relationNestedConfig)) {- const updatedValues =- await this.relationNestedQueries.processRelationNestedQueries({- entities: input.partialEntity as- | QueryDeepPartialEntityWithNestedRelationFields<T>- | QueryDeepPartialEntityWithNestedRelationFields<T>[],- relationNestedConfig: this.relationNestedConfig,- queryBuilder: nestedRelationQueryBuilder,- });-- this.expressionMap.valuesSet =- updatedValues.length === 1 ? updatedValues[0] : updatedValues;- }+ if (isDefined(this.relationNestedConfig)) {+ const updatedValues =+ await this.relationNestedQueries.processRelationNestedQueries({+ entities: this.manyInputs.map((input) => input.partialEntity) as+ | QueryDeepPartialEntityWithNestedRelationFields<T>+ | QueryDeepPartialEntityWithNestedRelationFields<T>[],+ relationNestedConfig: this.relationNestedConfig,+ queryBuilder: nestedRelationQueryBuilder,+ });++ this.manyInputs = updatedValues.map((updatedValue, index) => ({+ criteria: this.manyInputs[index].criteria,+ partialEntity: updatedValue,+ }));+ }++ for (const input of this.manyInputs) {+ this.expressionMap.valuesSet = input.partialEntity;+ this.where({ id: input.criteria });const result = await super.execute();