Skip to content

Commit

Permalink
Schema-accurate field names for relations (resolves #2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sukairo-02 committed Jul 2, 2024
1 parent a5bb5d6 commit 6760c28
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/util/generators/mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(', ')
Expand Down
2 changes: 1 addition & 1 deletion src/util/generators/pg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(', ')
Expand Down
2 changes: 1 addition & 1 deletion src/util/generators/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(', ')
Expand Down

0 comments on commit 6760c28

Please sign in to comment.