feat: new relation sync-metadata, twenty-orm, create/update (#10217)
Fix https://github.com/twentyhq/core-team-issues/issues/330#issue-2827026606 and https://github.com/twentyhq/core-team-issues/issues/327#issue-2827001814 What this PR does when `isNewRelationEnabled` is set to `true`: - [x] Drop the creation of the foreign key as a `FieldMetadata` - [x] Stop creating `RelationMetadata` - [x] Properly fill `FieldMetadata` of type `RELATION` during the sync command - [x] Use new relation settings in TwentyORM - [x] Properly create `FieldMetadata` relations when we create a new object - [x] Handle `database:reset` with new relations --------- Co-authored-by: Charles Bochet <charles@twenty.com> Co-authored-by: Charles Bochet <charlesBochet@users.noreply.github.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import { compositeTypeDefinitions } from 'src/engine/metadata-modules/field-meta
|
||||
import { isCompositeFieldMetadataType } from 'src/engine/metadata-modules/field-metadata/utils/is-composite-field-metadata-type.util';
|
||||
import { ObjectMetadataItemWithFieldMaps } from 'src/engine/metadata-modules/types/object-metadata-item-with-field-maps';
|
||||
import { CompositeFieldMetadataType } from 'src/engine/metadata-modules/workspace-migration/factories/composite-column-action.factory';
|
||||
import { isFieldMetadataInterfaceOfType } from 'src/engine/utils/is-field-metadata-of-type.util';
|
||||
|
||||
export function formatData<T>(
|
||||
data: T,
|
||||
@@ -23,9 +24,28 @@ export function formatData<T>(
|
||||
}
|
||||
|
||||
const newData: Record<string, any> = {};
|
||||
const fieldMetadataByJoinColumnName =
|
||||
objectMetadataItemWithFieldMaps.fields.reduce((acc, fieldMetadata) => {
|
||||
if (
|
||||
isFieldMetadataInterfaceOfType(
|
||||
fieldMetadata,
|
||||
FieldMetadataType.RELATION,
|
||||
)
|
||||
) {
|
||||
const joinColumnName = fieldMetadata.settings?.joinColumnName;
|
||||
|
||||
if (joinColumnName) {
|
||||
acc.set(joinColumnName, fieldMetadata);
|
||||
}
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, new Map<string, FieldMetadataInterface>());
|
||||
|
||||
for (const [key, value] of Object.entries(data)) {
|
||||
const fieldMetadata = objectMetadataItemWithFieldMaps.fieldsByName[key];
|
||||
const fieldMetadata =
|
||||
objectMetadataItemWithFieldMaps.fieldsByName[key] ||
|
||||
fieldMetadataByJoinColumnName.get(key);
|
||||
|
||||
if (!fieldMetadata) {
|
||||
throw new Error(
|
||||
|
||||
Reference in New Issue
Block a user