From 6760c2801fe3439cb5e635f1f01f0165e60f17e1 Mon Sep 17 00:00:00 2001 From: Sukairo-02 Date: Tue, 2 Jul 2024 13:47:22 +0300 Subject: [PATCH] Schema-accurate field names for relations (resolves #2) --- src/util/generators/mysql.ts | 2 +- src/util/generators/pg.ts | 2 +- src/util/generators/sqlite.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/util/generators/mysql.ts b/src/util/generators/mysql.ts index 2c40844..ad529fc 100755 --- a/src/util/generators/mysql.ts +++ b/src/util/generators/mysql.ts @@ -232,7 +232,7 @@ export const generateMySqlSchema = (options: GeneratorOptions) => { relationArgs.add(field.relationFromFields?.length ? 'one' : 'many'); const relName = s(field.relationName ?? ''); - return `\t'${relName}': ${ + return `\t${field.name}: ${ field.relationFromFields?.length ? `one(${field.type}, {\n\t\trelationName: '${relName}',\n\t\tfields: [${ field.relationFromFields.map((e) => `${schemaTable.name}.${e}`).join(', ') diff --git a/src/util/generators/pg.ts b/src/util/generators/pg.ts index 645fea4..68e9352 100755 --- a/src/util/generators/pg.ts +++ b/src/util/generators/pg.ts @@ -252,7 +252,7 @@ export const generatePgSchema = (options: GeneratorOptions) => { relationArgs.add(field.relationFromFields?.length ? 'one' : 'many'); const relName = s(field.relationName ?? ''); - return `\t'${relName}': ${ + return `\t${field.name}: ${ field.relationFromFields?.length ? `one(${field.type}, {\n\t\trelationName: '${relName}',\n\t\tfields: [${ field.relationFromFields.map((e) => `${schemaTable.name}.${e}`).join(', ') diff --git a/src/util/generators/sqlite.ts b/src/util/generators/sqlite.ts index a924218..57a7739 100755 --- a/src/util/generators/sqlite.ts +++ b/src/util/generators/sqlite.ts @@ -222,7 +222,7 @@ export const generateSQLiteSchema = (options: GeneratorOptions) => { relationArgs.add(field.relationFromFields?.length ? 'one' : 'many'); const relName = s(field.relationName ?? ''); - return `\t'${relName}': ${ + return `\t${field.name}: ${ field.relationFromFields?.length ? `one(${field.type}, {\n\t\trelationName: '${relName}',\n\t\tfields: [${ field.relationFromFields.map((e) => `${schemaTable.name}.${e}`).join(', ')