feat: manually implement joinColumn (#6022)

This PR introduce a new decorator named `@WorkspaceJoinColumn`, the goal
of this one is to manually declare the join columns inside the workspace
entities, so we don't have to rely on `ObjectRecord` type.

This decorator can be used that way:

```typescript
  @WorkspaceRelation({
    standardId: ACTIVITY_TARGET_STANDARD_FIELD_IDS.company,
    type: RelationMetadataType.MANY_TO_ONE,
    label: 'Company',
    description: 'ActivityTarget company',
    icon: 'IconBuildingSkyscraper',
    inverseSideTarget: () => CompanyWorkspaceEntity,
    inverseSideFieldKey: 'activityTargets',
  })
  @WorkspaceIsNullable()
  company: Relation<CompanyWorkspaceEntity> | null;

  // The argument is the name of the relation above
  @WorkspaceJoinColumn('company')
  companyId: string | null;
```
This commit is contained in:
Jérémy M
2024-06-27 11:41:22 +02:00
committed by GitHub
parent 7eb69a78ef
commit 95c5602a4e
64 changed files with 427 additions and 243 deletions

View File

@ -3,7 +3,6 @@ import { Injectable } from '@nestjs/common';
import { EntityManager } from 'typeorm';
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
import { ObjectRecord } from 'src/engine/workspace-manager/workspace-sync-metadata/types/object-record';
import { PersonWorkspaceEntity } from 'src/modules/person/standard-objects/person.workspace-entity';
import { getFlattenedValuesAndValuesStringForBatchRawQuery } from 'src/modules/calendar/utils/get-flattened-values-and-values-string-for-batch-raw-query.util';
@ -17,7 +16,7 @@ export class PersonRepository {
emails: string[],
workspaceId: string,
transactionManager?: EntityManager,
): Promise<ObjectRecord<PersonWorkspaceEntity>[]> {
): Promise<PersonWorkspaceEntity[]> {
const dataSourceSchema =
this.workspaceDataSourceService.getSchemaName(workspaceId);
@ -56,7 +55,7 @@ export class PersonRepository {
}[],
workspaceId: string,
transactionManager?: EntityManager,
): Promise<ObjectRecord<PersonWorkspaceEntity>[]> {
): Promise<PersonWorkspaceEntity[]> {
const dataSourceSchema =
this.workspaceDataSourceService.getSchemaName(workspaceId);

View File

@ -23,6 +23,7 @@ import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-
import { WorkspaceIsSystem } from 'src/engine/twenty-orm/decorators/workspace-is-system.decorator';
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
import { MessageParticipantWorkspaceEntity } from 'src/modules/messaging/common/standard-objects/message-participant.workspace-entity';
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
@WorkspaceEntity({
standardId: STANDARD_OBJECT_IDS.person,
@ -127,13 +128,15 @@ export class PersonWorkspaceEntity extends BaseWorkspaceEntity {
label: 'Company',
description: 'Contacts company',
icon: 'IconBuildingSkyscraper',
joinColumn: 'companyId',
inverseSideTarget: () => CompanyWorkspaceEntity,
inverseSideFieldKey: 'people',
})
@WorkspaceIsNullable()
company: Relation<CompanyWorkspaceEntity> | null;
@WorkspaceJoinColumn('company')
companyId: string | null;
@WorkspaceRelation({
standardId: PERSON_STANDARD_FIELD_IDS.pointOfContactForOpportunities,
type: RelationMetadataType.ONE_TO_MANY,