[Fix] fix relations in apps (#17791)
When syncing an app with relation multiple times, it would fail because the relation fields could not be identified due to universalIdentifier being overwritten at field cretion
This commit is contained in:
+48
@@ -349,4 +349,52 @@ describe('generate Morph Or Relation Flat Field Metadata Pair test suite', () =>
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe('Universal identifier behaviour', () => {
|
||||
it('should keep the source field universalIdentifier from createFieldInput', () => {
|
||||
const sourceUniversalIdentifier = '11111111-2222-3333-4444-555555555555';
|
||||
|
||||
const input: GenerateMorphOrRelationFlatFieldMetadataPairTestInput = {
|
||||
sourceFlatObjectMetadata: COMPANY_FLAT_OBJECT_MOCK,
|
||||
targetFlatObjectMetadata: PET_FLAT_OBJECT_MOCK,
|
||||
targetFlatFieldMetadataType: FieldMetadataType.RELATION,
|
||||
sourceFlatObjectMetadataJoinColumnName: 'petId',
|
||||
workspaceId: mockWorkspaceId,
|
||||
flatApplication: MOCK_FLAT_APPLICATION,
|
||||
createFieldInput: {
|
||||
name: 'pets',
|
||||
label: 'Pets',
|
||||
description: 'Company pets',
|
||||
icon: 'IconCat',
|
||||
type: FieldMetadataType.RELATION,
|
||||
objectMetadataId: COMPANY_FLAT_OBJECT_MOCK.id,
|
||||
isCustom: true,
|
||||
isSystem: false,
|
||||
isUnique: false,
|
||||
universalIdentifier: sourceUniversalIdentifier,
|
||||
relationCreationPayload: {
|
||||
type: RelationType.ONE_TO_MANY,
|
||||
targetObjectMetadataId: PET_FLAT_OBJECT_MOCK.id,
|
||||
targetFieldLabel: 'Company',
|
||||
targetFieldIcon: 'IconBuildingSkyscraper',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const result: SourceTargetMorphOrRelationFlatFieldAndFlatIndex =
|
||||
generateMorphOrRelationFlatFieldMetadataPair(input);
|
||||
|
||||
const [sourceFieldMetadata, targetFieldMetadata] =
|
||||
result.flatFieldMetadatas;
|
||||
|
||||
expect(sourceFieldMetadata.universalIdentifier).toBe(
|
||||
sourceUniversalIdentifier,
|
||||
);
|
||||
|
||||
expect(targetFieldMetadata.universalIdentifier).toBeDefined();
|
||||
expect(targetFieldMetadata.universalIdentifier).not.toBe(
|
||||
sourceUniversalIdentifier,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
+2
-6
@@ -107,7 +107,6 @@ export const generateMorphOrRelationFlatFieldMetadataPair = ({
|
||||
});
|
||||
const targetRelationTargetFieldMetadataId = v4();
|
||||
const sourceRelationTargetFieldMetadataId = v4();
|
||||
const sourceFieldUniversalIdentifier = v4();
|
||||
const targetFieldUniversalIdentifier = v4();
|
||||
|
||||
const defaultDescriptionFromField =
|
||||
@@ -125,10 +124,7 @@ export const generateMorphOrRelationFlatFieldMetadataPair = ({
|
||||
'flatRelationTargetFieldMetadata'
|
||||
> = {
|
||||
...getDefaultFlatFieldMetadata({
|
||||
createFieldInput: {
|
||||
...createFieldInput,
|
||||
universalIdentifier: sourceFieldUniversalIdentifier,
|
||||
},
|
||||
createFieldInput,
|
||||
workspaceId,
|
||||
fieldMetadataId: sourceRelationTargetFieldMetadataId,
|
||||
flatApplication,
|
||||
@@ -212,7 +208,7 @@ export const generateMorphOrRelationFlatFieldMetadataPair = ({
|
||||
relationTargetObjectMetadataUniversalIdentifier:
|
||||
sourceFlatObjectMetadata.universalIdentifier,
|
||||
relationTargetFieldMetadataUniversalIdentifier:
|
||||
sourceFieldUniversalIdentifier,
|
||||
sourceFlatFieldMetadata.universalIdentifier,
|
||||
};
|
||||
|
||||
const indexMetadata: FlatIndexMetadata = generateIndexForFlatFieldMetadata({
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ export const validateRelationCreationPayload = async ({
|
||||
errors: [
|
||||
{
|
||||
code: FieldMetadataExceptionCode.FIELD_METADATA_RELATION_MALFORMED,
|
||||
message: `Relation creation payload is invalid`,
|
||||
message: error.message ?? `Relation creation payload is invalid`,
|
||||
userFriendlyMessage: msg`Invalid relation creation payload`,
|
||||
value: relationCreationPayload,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user