From d20b322f80e066e7f974772251e35983375be520 Mon Sep 17 00:00:00 2001 From: Vasil Rangelov Date: Fri, 19 Jul 2019 15:49:18 +0300 Subject: [PATCH] Adds "?" to property names, to make the generated code compatible with "strictPropertyInitialization" TS setting. Also adds a call to super() when in active record mode, to make tslint play nice. --- src/entity.mst | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/entity.mst b/src/entity.mst index 634a2bb..c918696 100644 --- a/src/entity.mst +++ b/src/entity.mst @@ -24,21 +24,23 @@ import {BaseEntity,Column,Entity,Index,JoinColumn,JoinTable,ManyToMany,ManyToOne array:{{array}},{{/array}} name:"{{name}}" }){{/options}} - {{printPropertyVisibility}}{{toPropertyName tsName}}:{{tsType}}{{#options/nullable}} | null{{/options/nullable}}; + {{printPropertyVisibility}}{{toPropertyName tsName}}?:{{tsType}}{{#options/nullable}} | null{{/options/nullable}}; {{/relations}}{{#relations}} - @{{relationType}}(()=>{{toEntityName relatedTable}}, {{tolowerCaseFirst relatedTable}}=>{{tolowerCaseFirst 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}} + @{{relationType}}(()=>{{toEntityName relatedTable}}, ({{toPropertyName relatedTable}}: {{toEntityName relatedTable}})=>{{toPropertyName 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({ 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 (or isOneToMany isManyToMany)}}{{printPropertyVisibility}}{{toPropertyName ../tsName}}?:{{toLazy (concat (toEntityName relatedTable) "[]")}}; + {{else}}{{printPropertyVisibility}}{{toPropertyName ../tsName}}?:{{toLazy (concat (toEntityName relatedTable) ' | null')}}; {{/if}} {{#if relationIdField }} @RelationId(({{toPropertyName ../../tsEntityName}}: {{toEntityName ../../tsEntityName}}) => {{toEntityName ../../tsEntityName}}.{{toPropertyName ../tsName}}) - {{printPropertyVisibility}}{{toPropertyName ../tsName}}Id: {{#if isOneToOne}}{{toLazy ../tsType}}{{else}}{{toLazy (concat ../tsType "[]")}}{{/if}};{{/if}}{{/relations}} + {{printPropertyVisibility}}{{toPropertyName ../tsName}}Id?: {{#if isOneToOne}}{{toLazy ../tsType}}{{else}}{{toLazy (concat ../tsType "[]")}}{{/if}};{{/if}}{{/relations}} {{/Columns}} {{#if GenerateConstructor}} - constructor(init?: Partial<{{toEntityName tsEntityName}}>) { - Object.assign(this, init); + + public constructor(init?: Partial<{{toEntityName tsEntityName}}>) { + {{#IsActiveRecord}}super(); + {{/IsActiveRecord}}Object.assign(this, init); } {{/if}} }