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:
@ -17,6 +17,7 @@ import { WorkspaceField } from 'src/engine/twenty-orm/decorators/workspace-field
|
||||
import { WorkspaceRelation } from 'src/engine/twenty-orm/decorators/workspace-relation.decorator';
|
||||
import { WorkspaceIsNullable } from 'src/engine/twenty-orm/decorators/workspace-is-nullable.decorator';
|
||||
import { BaseWorkspaceEntity } from 'src/engine/twenty-orm/base.workspace-entity';
|
||||
import { WorkspaceJoinColumn } from 'src/engine/twenty-orm/decorators/workspace-join-column.decorator';
|
||||
|
||||
@WorkspaceEntity({
|
||||
standardId: STANDARD_OBJECT_IDS.activity,
|
||||
@ -131,11 +132,13 @@ export class ActivityWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
inverseSideTarget: () => WorkspaceMemberWorkspaceEntity,
|
||||
inverseSideFieldKey: 'authoredActivities',
|
||||
onDelete: RelationOnDeleteAction.SET_NULL,
|
||||
joinColumn: 'authorId',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
author: Relation<WorkspaceMemberWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('author')
|
||||
authorId: string | null;
|
||||
|
||||
@WorkspaceRelation({
|
||||
standardId: ACTIVITY_STANDARD_FIELD_IDS.assignee,
|
||||
label: 'Assignee',
|
||||
@ -145,8 +148,10 @@ export class ActivityWorkspaceEntity extends BaseWorkspaceEntity {
|
||||
inverseSideTarget: () => WorkspaceMemberWorkspaceEntity,
|
||||
inverseSideFieldKey: 'assignedActivities',
|
||||
onDelete: RelationOnDeleteAction.SET_NULL,
|
||||
joinColumn: 'assigneeId',
|
||||
})
|
||||
@WorkspaceIsNullable()
|
||||
assignee: Relation<WorkspaceMemberWorkspaceEntity> | null;
|
||||
|
||||
@WorkspaceJoinColumn('assignee')
|
||||
assigneeId: string | null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user