From 18482ebb55425593367fa5ef4cbadf8c9b7af677 Mon Sep 17 00:00:00 2001 From: "francesco.spilla" Date: Mon, 27 Dec 2021 20:50:48 +0100 Subject: [PATCH] add remove columns in relation option --- src/IGenerationOptions.ts | 2 ++ src/ModelCustomization.ts | 6 +++++- src/index.ts | 16 ++++++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/IGenerationOptions.ts b/src/IGenerationOptions.ts index a9812f3..f1b785d 100644 --- a/src/IGenerationOptions.ts +++ b/src/IGenerationOptions.ts @@ -24,6 +24,7 @@ export default interface IGenerationOptions { indexFile: boolean; exportType: "named" | "default"; skipNonPrimaryKeyIndexes: boolean; + removeColumnsInRelation: boolean; } export const eolConverter = { @@ -51,6 +52,7 @@ export function getDefaultGenerationOptions(): IGenerationOptions { indexFile: false, exportType: "named", skipNonPrimaryKeyIndexes: false, + removeColumnsInRelation: true, }; return generationOptions; } diff --git a/src/ModelCustomization.ts b/src/ModelCustomization.ts index 711632a..e093b9e 100644 --- a/src/ModelCustomization.ts +++ b/src/ModelCustomization.ts @@ -89,7 +89,11 @@ export default function modelCustomizationPhase( } namingStrategy.enablePluralization(generationOptions.pluralizeNames); let retVal = removeIndicesGeneratedByTypeorm(dbModel); - retVal = removeColumnsInRelation(dbModel); + + if (generationOptions.removeColumnsInRelation) { + retVal = removeColumnsInRelation(dbModel); + } + retVal = applyNamingStrategy(namingStrategy, dbModel); retVal = addImportsAndGenerationOptions(retVal, generationOptions); retVal = removeColumnDefaultProperties(retVal, defaultValues); diff --git a/src/index.ts b/src/index.ts index e5c9ff2..cd24408 100644 --- a/src/index.ts +++ b/src/index.ts @@ -281,7 +281,12 @@ function checkYargsParameters(options: options): options { boolean: true, default: options.generationOptions.skipNonPrimaryKeyIndexes, describe: "Skip generation of non-primary key indexes", - }, + }, + removeColumnsInRelation: { + boolean: true, + default: options.generationOptions.removeColumnsInRelation, + describe: "Remove columns in relation", + }, tables: { string: true, default: options.connectionOptions.onlyTables.join(","), @@ -348,6 +353,7 @@ function checkYargsParameters(options: options): options { options.generationOptions.relationIds = argv.relationIds; options.generationOptions.skipSchema = argv.skipSchema; options.generationOptions.skipNonPrimaryKeyIndexes = argv.skipNonPrimaryKeyIndexes; + options.generationOptions.removeColumnsInRelation = argv.removeColumnsInRelation; options.generationOptions.resultsPath = argv.o; options.generationOptions.pluralizeNames = !argv.disablePluralization; options.generationOptions.strictMode = @@ -625,7 +631,12 @@ async function useInquirer(options: options): Promise { name: "Skip generation of non-primary key indexes", value: "skipNonPrimaryKeyIndexes", checked: options.generationOptions.skipNonPrimaryKeyIndexes, - } + }, + { + name: "Remove columns in relation", + value: "removeColumnsInRelation", + checked: options.generationOptions.removeColumnsInRelation, + } ], message: "Available customizations", name: "selected", @@ -679,6 +690,7 @@ async function useInquirer(options: options): Promise { ? "default" : "named"; options.generationOptions.skipNonPrimaryKeyIndexes = customizations.includes("skipNonPrimaryKeyIndexes"); + options.generationOptions.removeColumnsInRelation = customizations.includes("removeColumnsInRelation"); if (customizations.includes("namingStrategy")) { const namingStrategyPath = (