Complete the code to define a OneToMany relation from User to Post.
import { Entity, PrimaryGeneratedColumn, Column, [1] } from 'typeorm'; @Entity() export class User { @PrimaryGeneratedColumn() id: number; @Column() name: string; @[1](() => Post, post => post.user) posts: Post[]; }
The OneToMany decorator defines a one-to-many relation from User to Post.
Complete the code to define the ManyToOne side of the relation from Post to User.
import { Entity, PrimaryGeneratedColumn, Column, [1] } from 'typeorm'; @Entity() export class Post { @PrimaryGeneratedColumn() id: number; @Column() title: string; @[1](() => User, user => user.posts) user: User; }
The ManyToOne decorator defines the many-to-one side from Post to User.
Fix the error in the ManyToMany relation between Student and Course by completing the decorator.
import { Entity, PrimaryGeneratedColumn, Column, [1] } from 'typeorm'; @Entity() export class Student { @PrimaryGeneratedColumn() id: number; @Column() name: string; @[1](() => Course, course => course.students) courses: Course[]; }
The ManyToMany decorator is used to define many-to-many relations like between Student and Course.
Fill both blanks to complete the ManyToMany relation with JoinTable between Course and Student.
import { Entity, PrimaryGeneratedColumn, Column, [1], [2] } from 'typeorm'; @Entity() export class Course { @PrimaryGeneratedColumn() id: number; @Column() title: string; @ManyToMany(() => Student, student => student.courses) @[2]() students: Student[]; }
The ManyToMany decorator defines the relation, and JoinTable creates the join table in the database.
Fill all three blanks to create a OneToMany and ManyToOne relation between Author and Book with proper imports and decorators.
import { Entity, PrimaryGeneratedColumn, Column, [1], [2], [3] } from 'typeorm'; @Entity() export class Author { @PrimaryGeneratedColumn() id: number; @Column() name: string; @[2](() => Book, book => book.author) books: Book[]; } @Entity() export class Book { @PrimaryGeneratedColumn() id: number; @Column() title: string; @[3](() => Author, author => author.books) author: Author; }
Import OneToMany, ManyToOne, and JoinColumn as needed. Use OneToMany on Author's books and ManyToOne on Book's author.