Repository: twentyhq/twenty
File: packages/twenty-sdk/src/cli/utilities/build/manifest/utils/get-default-relation-object-fields.ts (TypeScript)

Code before:
  objectConfig: ObjectConfig,
): { objectFields: ObjectFieldManifest[]; fields: FieldManifest[] } => {
  const objectFields: ObjectFieldManifest[] = [];
  const fields: FieldManifest[] = [];

  for (const config of DEFAULT_RELATION_CONFIGS) {
    const standardObject = STANDARD_OBJECTS[config.standardObjectKey];

    const forwardFieldUniversalIdentifier =
      generateDefaultFieldUniversalIdentifier({
        objectConfig,
        fieldName: config.fieldName,
      });

    const reverseFieldUniversalIdentifier =
      generateDefaultFieldUniversalIdentifier({
        objectConfig,
        fieldName: `${config.fieldName}Inverse`,
      });

    const forwardField: ObjectFieldManifest = {
      name: config.fieldName,
      label: config.label,
      description: `${objectConfig.labelPlural} tied to the ${config.targetLabel(objectConfig)}`,
      icon: config.icon,
      isNullable: true,
      type: FieldMetadataType.RELATION,
      universalSettings: { relationType: RelationType.ONE_TO_MANY },
      universalIdentifier: forwardFieldUniversalIdentifier,
      relationTargetFieldMetadataUniversalIdentifier:
        reverseFieldUniversalIdentifier,
      relationTargetObjectMetadataUniversalIdentifier:
        standardObject.universalIdentifier,
    };

    const reverseField = buildReverseField({
      config,
      objectConfig,
      universalIdentifier: reverseFieldUniversalIdentifier,
      forwardFieldUniversalIdentifier,
    });

    objectFields.push(forwardField);
    fields.push(reverseField);
  }

  return { objectFields, fields };
};


Review comment (suggestion):
I don't get this change. I'm also confused because it seems our FK are actually non-nullable already so it's probably ignored? Anyway, this is probably a good change but this seems unused so it could be confusing. Not on you though

Code after:
  objectConfig: ObjectConfig,
): { objectFields: ObjectFieldManifest[]; fields: FieldManifest[] } => {
  const objectFields: ObjectFieldManifest[] = [];
  const fields: FieldManifest[] = [];

  for (const config of DEFAULT_RELATION_CONFIGS) {
    const standardObject = STANDARD_OBJECTS[config.standardObjectKey];

    const forwardFieldUniversalIdentifier =
      generateDefaultFieldUniversalIdentifier({
        objectConfig,
        fieldName: config.fieldName,
      });

    const reverseFieldUniversalIdentifier =
      generateDefaultFieldUniversalIdentifier({
        objectConfig,
        fieldName: `${config.fieldName}Inverse`,
      });

    const forwardField: ObjectFieldManifest = {
      name: config.fieldName,
      label: config.label,
      description: `${objectConfig.labelPlural} tied to the ${config.targetLabel(objectConfig)}`,
      icon: config.icon,
      isNullable: config.isNullable,
      type: FieldMetadataType.RELATION,
      universalSettings: { relationType: RelationType.ONE_TO_MANY },
      universalIdentifier: forwardFieldUniversalIdentifier,
      relationTargetFieldMetadataUniversalIdentifier:
        reverseFieldUniversalIdentifier,
      relationTargetObjectMetadataUniversalIdentifier:
        standardObject.universalIdentifier,
    };

    const reverseField = buildReverseField({
      config,
      objectConfig,
      universalIdentifier: reverseFieldUniversalIdentifier,
      forwardFieldUniversalIdentifier,
    });

    objectFields.push(forwardField);
    fields.push(reverseField);
  }

  return { objectFields, fields };
};