From 31ecaf2a0de6ec3a58c4cda9196732030d7f5e76 Mon Sep 17 00:00:00 2001 From: Weiko Date: Tue, 29 Oct 2024 15:45:27 +0100 Subject: [PATCH] fix object metadata renaming (#8175) ## Context Latest refactoring broke the findOneWithinWorkspace method which is called during object update, I'm simply reverting this change. object-metadata-relation.service was naively computing a namePlural based on the nameSingular while we already had that info in the DB... Should fix some issues with renaming as well because the original field was not computed with the right name. --- .../object-metadata.service.ts | 42 +++++++++++++------ .../object-metadata-relation.service.ts | 5 +-- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/packages/twenty-server/src/engine/metadata-modules/object-metadata/object-metadata.service.ts b/packages/twenty-server/src/engine/metadata-modules/object-metadata/object-metadata.service.ts index 2e6b41605e99..46964cebbd5c 100644 --- a/packages/twenty-server/src/engine/metadata-modules/object-metadata/object-metadata.service.ts +++ b/packages/twenty-server/src/engine/metadata-modules/object-metadata/object-metadata.service.ts @@ -320,33 +320,36 @@ export class ObjectMetadataService extends TypeOrmQueryService) { - return this.objectMetadataRepository.find({ + public async findOneWithinWorkspace( + workspaceId: string, + options: FindOneOptions, + ): Promise { + return this.objectMetadataRepository.findOne({ relations: [ 'fields', 'fields.fromRelationMetadata', 'fields.toRelationMetadata', - 'fields.fromRelationMetadata.toObjectMetadata', ], ...options, where: { - ...options?.where, + ...options.where, + workspaceId, }, }); } - public async findOneWithinWorkspace( - workspaceId: string, - options: FindOneOptions, - ): Promise { - return this.findManyWithinWorkspace(workspaceId, options)[0] ?? null; - } - public async findManyWithinWorkspace( workspaceId: string, options?: FindManyOptions, ) { - return this.findMany({ + return this.objectMetadataRepository.find({ + relations: [ + 'fields.object', + 'fields', + 'fields.fromRelationMetadata', + 'fields.toRelationMetadata', + 'fields.fromRelationMetadata.toObjectMetadata', + ], ...options, where: { ...options?.where, @@ -355,6 +358,21 @@ export class ObjectMetadataService extends TypeOrmQueryService) { + return this.objectMetadataRepository.find({ + relations: [ + 'fields', + 'fields.fromRelationMetadata', + 'fields.toRelationMetadata', + 'fields.fromRelationMetadata.toObjectMetadata', + ], + ...options, + where: { + ...options?.where, + }, + }); + } + public async deleteObjectsMetadata(workspaceId: string) { await this.objectMetadataRepository.delete({ workspaceId }); await this.workspaceMetadataVersionService.incrementMetadataVersion( diff --git a/packages/twenty-server/src/engine/metadata-modules/object-metadata/services/object-metadata-relation.service.ts b/packages/twenty-server/src/engine/metadata-modules/object-metadata/services/object-metadata-relation.service.ts index a8054bdadb51..68f35492c3c0 100644 --- a/packages/twenty-server/src/engine/metadata-modules/object-metadata/services/object-metadata-relation.service.ts +++ b/packages/twenty-server/src/engine/metadata-modules/object-metadata/services/object-metadata-relation.service.ts @@ -139,8 +139,7 @@ export class ObjectMetadataRelationService { createdObjectMetadata: ObjectMetadataEntity, relatedObjectMetadata: ObjectMetadataEntity, ) { - const relationObjectMetadataNamePlural = - relatedObjectMetadata.nameSingular + 's'; + const relationObjectMetadataNamePlural = relatedObjectMetadata.namePlural; return { standardId: @@ -151,7 +150,7 @@ export class ObjectMetadataRelationService { isActive: true, isSystem: true, type: FieldMetadataType.RELATION, - name: relationObjectMetadataNamePlural, + name: relatedObjectMetadata.namePlural, label: capitalize(relationObjectMetadataNamePlural), description: `${capitalize(relationObjectMetadataNamePlural)} tied to the ${createdObjectMetadata.labelSingular}`, icon: