#71 relation onUpdate

This commit is contained in:
Kononnable 2018-08-26 01:19:28 +02:00
parent 4a32d103a5
commit f3a79c2e38
9 changed files with 152 additions and 5 deletions

View File

@ -24,7 +24,7 @@ import {Index,Entity, PrimaryColumn, Column, OneToOne, OneToMany, ManyToOne, Man
})
{{toPropertyName tsName}}:{{ts_type}}{{#is_nullable}} | null{{/is_nullable}};
{{/relations}}{{#relations}}
@{{relationType}}(type=>{{toEntityName relatedTable}}, {{toEntityName relatedTable}}=>{{toEntityName relatedTable}}.{{#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}}
@{{relationType}}(type=>{{toEntityName relatedTable}}, {{toEntityName relatedTable}}=>{{toEntityName relatedTable}}.{{#if isOwner}}{{toPropertyName ownerColumn}},{ {{#../isPrimary}}primary:true,{{/../isPrimary}}{{^../is_nullable}} nullable:false,{{/../is_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:'{{ ../sqlName}}'}){{/if}}{{/isOwner}}
{{#if (or isOneToMany isManyToMany)}}{{toPropertyName ../tsName}}:{{toLazy (concat (toEntityName relatedTable) "[]")}};
{{else}}{{toPropertyName ../tsName}}:{{toLazy (concat (toEntityName relatedTable) ' | null')}};

View File

@ -5,8 +5,14 @@ export class RelationInfo {
relatedColumn: string;
ownerTable: string;
ownerColumn: string;
actionOnDelete: "RESTRICT" | "CASCADE" | "SET NULL" | null;
actionOnUpdate: "RESTRICT" | "CASCADE" | "SET NULL" | null;
actionOnDelete:
| "RESTRICT"
| "CASCADE"
| "SET NULL"
| "DEFAULT"
| "NO ACTION"
| null;
actionOnUpdate: "RESTRICT" | "CASCADE" | "SET NULL" | "DEFAULT" | null;
relationIdField: boolean = false;
get isOneToMany(): boolean {

View File

@ -3,7 +3,13 @@ interface RelationTempInfo {
ownerColumnsNames: string[];
referencedTable: string;
referencedColumnsNames: string[];
actionOnDelete: "RESTRICT" | "CASCADE" | "SET NULL" | null;
actionOnUpdate: "RESTRICT" | "CASCADE" | "SET NULL" | null;
actionOnDelete:
| "RESTRICT"
| "CASCADE"
| "SET NULL"
| "DEFAULT"
| "NO ACTION"
| null;
actionOnUpdate: "RESTRICT" | "CASCADE" | "SET NULL" | "DEFAULT" | null;
object_id: number | string;
}

View File

@ -0,0 +1,41 @@
import { Index, Entity, PrimaryColumn, Column, OneToOne, OneToMany, ManyToOne, ManyToMany, JoinColumn, JoinTable } from "typeorm";
import { PostReader } from "./PostReader";
import { PostAuthor } from "./PostAuthor";
import { PostCategory } from "./PostCategory";
import { PostDetails } from "./PostDetails";
@Entity("Post")
export class Post {
@Column("int", {
nullable: false,
primary: true,
name: "Id"
})
Id: number;
@OneToOne(type => PostAuthor, PostAuthor => PostAuthor.Id,
{
// onDelete: "CASCADE",
// onUpdate: "CASCADE"
})
postAuthor: PostAuthor;
@OneToOne(type => PostReader, PostReader => PostReader.Id)
postReader: PostReader;
@OneToOne(type => PostCategory, PostCategory => PostCategory.Id,
{
// onDelete: "RESTRICT",
// onUpdate: "RESTRICT"
})
postCategory: PostCategory;
@OneToOne(type => PostDetails, PostDetails => PostDetails.Id,
{
// onDelete: "SET NULL",
// onUpdate: "SET NULL"
})
postDetails: PostDetails;
}

View File

@ -0,0 +1,24 @@
import {Index,Entity, PrimaryColumn, Column, OneToOne, OneToMany, ManyToOne, ManyToMany, JoinColumn, JoinTable, RelationId} from "typeorm";
import { Post } from "./Post";
@Entity("PostAuthor")
export class PostAuthor {
@Column("int",{
nullable:false,
primary:true,
name:"Id"
})
Id:number;
@OneToOne(type => Post, Post => Post.Id,{
onDelete: "CASCADE",
// onUpdate: "CASCADE"
})
@JoinColumn()
post:Post;
}

View File

@ -0,0 +1,25 @@
import {Index,Entity, PrimaryColumn, Column, OneToOne, OneToMany, ManyToOne, ManyToMany, JoinColumn, JoinTable, RelationId} from "typeorm";
import { Post } from "./Post";
@Entity("PostCategory")
export class PostCategory {
@Column("int",{
nullable:false,
primary:true,
name:"Id"
})
Id:number;
@OneToOne(type => Post, Post => Post.Id,
{
// onDelete: "RESTRICT",
// onUpdate: "RESTRICT"
})
@JoinColumn()
post:Post;
}

View File

@ -0,0 +1,23 @@
import {Index,Entity, PrimaryColumn, Column, OneToOne, OneToMany, ManyToOne, ManyToMany, JoinColumn, JoinTable, RelationId} from "typeorm";
import { Post } from "./Post";
@Entity("PostDetails")
export class PostDetails {
@Column("int",{
nullable:false,
primary:true,
name:"Id"
})
Id:number;
@OneToOne(type => Post, Post => Post.Id,
{
onDelete: "SET NULL",
// onUpdate: "SET NULL"
})
@JoinColumn()
post:Post;
}

View File

@ -0,0 +1,19 @@
import {Index,Entity, PrimaryColumn, Column, OneToOne, OneToMany, ManyToOne, ManyToMany, JoinColumn, JoinTable, RelationId} from "typeorm";
import { Post } from "./Post";
@Entity("PostReader")
export class PostReader {
@Column("int",{
nullable:false,
primary:true,
name:"Id"
})
Id:number;
@OneToOne(type => Post, Post => Post.Id)
@JoinColumn()
post:Post;
}

View File

@ -41,6 +41,9 @@ describe("GitHub issues", async function () {
if (dbDriver == 'mysql' || dbDriver == 'mariadb' || dbDriver == 'oracle' || dbDriver == 'sqlite')
continue;
break;
// case '71':
// xit(dbDriver);
// continue;
default:
break;
}