diff --git a/src/entity.mst b/src/entity.mst index cb702db..c2f712e 100644 --- a/src/entity.mst +++ b/src/entity.mst @@ -24,7 +24,7 @@ import {Index,Entity, PrimaryColumn, Column, OneToOne, OneToMany, ManyToOne, Man }) {{toPropertyName name}}:{{ts_type}}; {{/relations}}{{#relations}} - @{{relationType}}(type=>{{toEntityName relatedTable}}, {{toPropertyName ../name}}=>{{toPropertyName ../name}}.{{#if isOwner}}{{toPropertyName ownerColumn}},{ {{#../isPrimary}}primary:true,{{/../isPrimary}}{{^../is_nullable}} nullable:false,{{/../is_nullable}}{{#actionOnDelete}}onDelete: '{{.}}'{{/actionOnDelete}} }{{else}}{{toPropertyName relatedColumn}}{{#actionOnDelete}},{ onDelete: '{{.}}' }{{/actionOnDelete}}{{/if}}){{#isOwner}} + @{{relationType}}(type=>{{toEntityName relatedTable}}, {{toPropertyName ../name}}=>{{toPropertyName ../name}}.{{#if isOwner}}{{toPropertyName ownerColumn}},{ {{#../isPrimary}}primary:true,{{/../isPrimary}}{{^../is_nullable}} nullable:false,{{/../is_nullable}}{{#actionOnDelete}}onDelete: '{{.}}',{{/actionOnDelete}}{{#actionOnUpdate}}onUpdate: '{{.}}'{{/actionOnUpdate}} }{{else}}{{toPropertyName relatedColumn}}{{#actionOnDelete}},{ onDelete: '{{.}}' }{{/actionOnDelete}}{{/if}}){{#isOwner}} {{#if isManyToMany}}@JoinTable(){{else}}@JoinColumn({ name:'{{ ../name}}'}){{/if}}{{/isOwner}} {{#if (or isOneToMany isManyToMany)}}{{toPropertyName ../name}}:{{toLazy (concat (toEntityName relatedTable) "[]")}}; {{else}}{{toPropertyName ../name}}:{{toLazy (toEntityName relatedTable)}}; diff --git a/test/integration/examples/sample18-lazy-relations/entity/Post.ts b/test/integration/examples/sample18-lazy-relations/entity/Post.ts index 303ff25..88bfe40 100644 --- a/test/integration/examples/sample18-lazy-relations/entity/Post.ts +++ b/test/integration/examples/sample18-lazy-relations/entity/Post.ts @@ -1,6 +1,6 @@ import { Column, Entity, Index, PrimaryGeneratedColumn, ManyToOne, ManyToMany, JoinTable } from "typeorm" -import {Author} from "./Author"; -import {Category} from "./Category"; +import { Author } from "./Author"; +import { Category } from "./Category"; @Entity("Post") export class Post { @@ -16,9 +16,10 @@ export class Post { @ManyToOne(type => Author, author => author.posts, { // cascade: ["insert"], - onDelete: "SET NULL" + onDelete: "SET NULL", + onUpdate: "CASCADE" }) - author: Promise; + author: Promise; @ManyToMany(type => Category, category => category.Post, { // cascade: true