From aba47cc9b8379da1cfab0dc6cd1138ca3127aa5c Mon Sep 17 00:00:00 2001 From: Kononnable Date: Mon, 25 Feb 2019 23:23:07 +0100 Subject: [PATCH] fixes #151 - generation of ManyToMany relation with custom table names --- CHANGELOG.md | 2 ++ src/drivers/AbstractDriver.ts | 1 + src/entity.mst | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 851b368..07ef685 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +* fixed generation of ManyToMany relations on junction tables with custom names(#151) + ## 0.3.1 * Fixed npx ussage(#146) diff --git a/src/drivers/AbstractDriver.ts b/src/drivers/AbstractDriver.ts index 5bd555f..ec69693 100644 --- a/src/drivers/AbstractDriver.ts +++ b/src/drivers/AbstractDriver.ts @@ -113,6 +113,7 @@ export abstract class AbstractDriver { const column1 = new ColumnInfo(); column1.tsName = namesOfRelatedTables[1]; + column1.options.name = entity.sqlEntityName; const col1Rel = new RelationInfo(); col1Rel.relatedTable = namesOfRelatedTables[1]; diff --git a/src/entity.mst b/src/entity.mst index db27e03..65675c2 100644 --- a/src/entity.mst +++ b/src/entity.mst @@ -26,7 +26,7 @@ import {BaseEntity,Column,Entity,Index,JoinColumn,JoinTable,ManyToMany,ManyToOne {{printPropertyVisibility}}{{toPropertyName tsName}}:{{tsType}}{{#options/nullable}} | null{{/options/nullable}}; {{/relations}}{{#relations}} @{{relationType}}(type=>{{toEntityName relatedTable}}, {{toEntityName relatedTable}}=>{{toEntityName relatedTable}}.{{#if isOwner}}{{toPropertyName ownerColumn}},{ {{#../options/primary}}primary:true,{{/../options/primary}}{{^../options/nullable}} nullable:false,{{/../options/nullable}}{{#actionOnDelete}}onDelete: '{{.}}',{{/actionOnDelete}}{{#actionOnUpdate}}onUpdate: '{{.}}'{{/actionOnUpdate}} }{{else}}{{toPropertyName relatedColumn}}{{#if (or actionOnDelete actionOnUpdate ) }}{{#actionOnDelete}},{ onDelete: '{{.}}' ,{{/actionOnDelete}}{{#actionOnUpdate}}onUpdate: '{{.}}'{{/actionOnUpdate}} }{{/if}}{{/if}}){{#isOwner}} - {{#if isManyToMany}}@JoinTable(){{else}}@JoinColumn({ name:'{{ ../options/name}}'}){{/if}}{{/isOwner}} + {{#if isManyToMany}}@JoinTable({ name:'{{ ../options/name}}'}){{else}}@JoinColumn({ name:'{{ ../options/name}}'}){{/if}}{{/isOwner}} {{#if (or isOneToMany isManyToMany)}}{{printPropertyVisibility}}{{toPropertyName ../tsName}}:{{toLazy (concat (toEntityName relatedTable) "[]")}}; {{else}}{{printPropertyVisibility}}{{toPropertyName ../tsName}}:{{toLazy (concat (toEntityName relatedTable) ' | null')}}; {{/if}}