#71 relation onUpdate
This commit is contained in:
parent
4a32d103a5
commit
f3a79c2e38
@ -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')}};
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
|
41
test/integration/github-issues/71/entity/Post.ts
Normal file
41
test/integration/github-issues/71/entity/Post.ts
Normal 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;
|
||||
}
|
24
test/integration/github-issues/71/entity/PostAuthor.ts
Normal file
24
test/integration/github-issues/71/entity/PostAuthor.ts
Normal 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;
|
||||
|
||||
}
|
25
test/integration/github-issues/71/entity/PostCategory.ts
Normal file
25
test/integration/github-issues/71/entity/PostCategory.ts
Normal 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;
|
||||
|
||||
}
|
23
test/integration/github-issues/71/entity/PostDetails.ts
Normal file
23
test/integration/github-issues/71/entity/PostDetails.ts
Normal 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;
|
||||
|
||||
}
|
19
test/integration/github-issues/71/entity/PostReader.ts
Normal file
19
test/integration/github-issues/71/entity/PostReader.ts
Normal 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;
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user