Create Relation with Fields from both sides (#2480)

* Create relation with fields from both sides

* update metadata codegen schema
This commit is contained in:
Weiko 2023-11-13 17:22:15 +01:00 committed by GitHub
parent 05dbde79cf
commit 3de2fc72dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 19 deletions

View File

@ -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'];
};

View File

@ -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;
}

View File

@ -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,