/
Post.ts
41 lines (33 loc) · 1.61 KB
/
Post.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import {PrimaryGeneratedColumn, Column, Entity, OneToOne} from "../../../src/index";
import {PostAuthor} from "./PostAuthor";
import {JoinColumn} from "../../../src/decorator/relations/JoinColumn";
import {OneToMany} from "../../../src/decorator/relations/OneToMany";
import {JoinTable} from "../../../src/decorator/relations/JoinTable";
import {ManyToMany} from "../../../src/decorator/relations/ManyToMany";
@Entity("sample14_post")
export class Post {
@PrimaryGeneratedColumn()
id: number;
@Column()
title: string;
@Column()
text: string;
@OneToOne(type => PostAuthor, author => author.post, {
cascadeInsert: true,
cascadeUpdate: true,
cascadeRemove: true
})
@JoinColumn() // comment this and you'll get an error because JoinColumn must be at least on one side of the one-to-one relationship
// @JoinTable() // uncomment this and you'll get an error because JoinTable is not allowed here (only many-to-many)
author: PostAuthor;
@OneToMany(type => PostAuthor, author => author.editedPost, {
cascadeInsert: true,
cascadeUpdate: true
})
// @JoinColumn() // uncomment this and you'll get an error, because JoinColumn is not allowed here (only many-to-one/one-to-one)
// @JoinTable() // uncomment this and you'll get an error because JoinTable is not allowed here (only many-to-many)
editors: PostAuthor[];
@ManyToMany(type => PostAuthor, author => author.manyPosts)
@JoinTable() // comment this and you'll get an error because JoinTable must be at least on one side of the many-to-many relationship
manyAuthors: PostAuthor[];
}