mirror of
https://github.com/twentyhq/twenty.git
synced 2025-01-05 10:54:15 +03:00
Create Relation with Fields from both sides (#2480)
* Create relation with fields from both sides * update metadata codegen schema
This commit is contained in:
parent
05dbde79cf
commit
3de2fc72dc
@ -203,11 +203,14 @@ export type CreateOneRelationInput = {
|
||||
|
||||
export type CreateRelationInput = {
|
||||
description?: InputMaybe<Scalars['String']['input']>;
|
||||
fromIcon?: InputMaybe<Scalars['String']['input']>;
|
||||
fromLabel: Scalars['String']['input'];
|
||||
fromName: Scalars['String']['input'];
|
||||
fromObjectMetadataId: Scalars['String']['input'];
|
||||
icon?: InputMaybe<Scalars['String']['input']>;
|
||||
label: Scalars['String']['input'];
|
||||
name: Scalars['String']['input'];
|
||||
relationType: Scalars['String']['input'];
|
||||
toIcon?: InputMaybe<Scalars['String']['input']>;
|
||||
toLabel: Scalars['String']['input'];
|
||||
toName: Scalars['String']['input'];
|
||||
toObjectMetadataId: Scalars['String']['input'];
|
||||
};
|
||||
|
||||
|
@ -33,23 +33,38 @@ export class CreateRelationInput {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Field()
|
||||
name: string;
|
||||
fromName: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Field()
|
||||
label: string;
|
||||
toName: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Field()
|
||||
fromLabel: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Field()
|
||||
toLabel: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@Field({ nullable: true })
|
||||
fromIcon?: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@Field({ nullable: true })
|
||||
toIcon?: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@Field({ nullable: true })
|
||||
description?: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@Field({ nullable: true })
|
||||
icon?: string;
|
||||
|
||||
@HideField()
|
||||
workspaceId: string;
|
||||
}
|
||||
|
@ -64,11 +64,12 @@ export class RelationMetadataService extends TypeOrmQueryService<RelationMetadat
|
||||
}
|
||||
|
||||
const createdFields = await this.fieldMetadataService.createMany([
|
||||
// FROM
|
||||
{
|
||||
name: record.name,
|
||||
label: record.label,
|
||||
name: record.fromName,
|
||||
label: record.fromLabel,
|
||||
description: record.description,
|
||||
icon: record.icon,
|
||||
icon: record.fromIcon,
|
||||
isCustom: true,
|
||||
targetColumnMap: {},
|
||||
isActive: true,
|
||||
@ -76,14 +77,12 @@ export class RelationMetadataService extends TypeOrmQueryService<RelationMetadat
|
||||
objectMetadataId: record.fromObjectMetadataId,
|
||||
workspaceId: record.workspaceId,
|
||||
},
|
||||
// NOTE: Since we have to create the field-metadata for the user, we need to use the toObjectMetadata info.
|
||||
// This is not ideal because we might see some conflicts with existing names.
|
||||
// NOTE2: Once MANY_TO_MANY is supported, we need to use namePlural/labelPlural instead.
|
||||
// TO
|
||||
{
|
||||
name: objectMetadataMap[record.fromObjectMetadataId].nameSingular,
|
||||
label: objectMetadataMap[record.fromObjectMetadataId].labelSingular,
|
||||
name: record.toName,
|
||||
label: record.toLabel,
|
||||
description: undefined,
|
||||
icon: objectMetadataMap[record.fromObjectMetadataId].icon,
|
||||
icon: record.toIcon,
|
||||
isCustom: true,
|
||||
targetColumnMap: {},
|
||||
isActive: true,
|
||||
|
Loading…
Reference in New Issue
Block a user