Javascript 在NestJS中更新OneToMany关系
类似于: 我有两个实体(书本和学生): 及 每个学生都阅读书籍,一本书可以由一个学生阅读,一旦阅读,它就被标记为这样(isRead=true)。学生一次只能阅读一本书(社区学院…),并且只能在当前一本书完成后才开始阅读下一本书(学生和书可以彼此独立存在;关系(“阅读”)稍后建立 我所尝试的:Javascript 在NestJS中更新OneToMany关系,javascript,typescript,nestjs,typeorm,Javascript,Typescript,Nestjs,Typeorm,类似于: 我有两个实体(书本和学生): 及 每个学生都阅读书籍,一本书可以由一个学生阅读,一旦阅读,它就被标记为这样(isRead=true)。学生一次只能阅读一本书(社区学院…),并且只能在当前一本书完成后才开始阅读下一本书(学生和书可以彼此独立存在;关系(“阅读”)稍后建立 我所尝试的: // Get all students const currentStudent = await getConnection(). getRepository(Student). createQu
// Get all students
const currentStudent = await getConnection().
getRepository(Student).
createQueryBuilder().
leftJoinAndSelect("agent.assignedBooks", "assignedBooks").getMany();
// Iterate through books list; if all are read, add a new book (and
// save both the book, student and update relationship)
如何更新关系数组(在一个查询中)?这实际上是,而不是家庭作业
@Entity({ name: 'student' })
export class Student {
@PrimaryGeneratedColumn('uuid')
id: string;
@OneToMany(type => Book, assignedBooks => assignedBooks.assignedStudent, { cascade: ['insert', 'update'], nullable: true })
assignedBooks: Book[];
}
// Get all students
const currentStudent = await getConnection().
getRepository(Student).
createQueryBuilder().
leftJoinAndSelect("agent.assignedBooks", "assignedBooks").getMany();
// Iterate through books list; if all are read, add a new book (and
// save both the book, student and update relationship)