【发布时间】:2021-11-24 06:17:06
【问题描述】:
我是 Nestjs 的新手。我有两个实体:
@Entity({ name: "Books" })
@ObjectType()
export class Book {
@PrimaryGeneratedColumn()
@Field()
id: number;
@Column()
@Field()
title: string;
@ManyToMany(() => Author, (author: Author) => author.books)
@Field(() => [Author])
authors: Author[];
}
@Entity({ name: "Authors" })
@ObjectType()
export class Author {
@PrimaryGeneratedColumn()
@Field()
id: Number;
@Column()
@Field()
firstName: string;
@Column()
@Field()
lastName: string;
@ManyToMany(() => Book, (book: Book) => book.authors)
@JoinTable()
@Field(() => [Book])
books: Book[];
}
这会自动给我第三个空表“authors_books_books”。如何建立作者与书籍的关系?不仅在抽象作者和抽象书之间,而且指定这个作者的 id:x 写了这本书 id:y?换句话说:如何用数据填充“authors_books_books”表?
【问题讨论】:
标签: typescript graphql nestjs apollo typeorm