Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在NestJS中更新OneToMany关系_Javascript_Typescript_Nestjs_Typeorm - Fatal编程技术网

Javascript 在NestJS中更新OneToMany关系

Javascript 在NestJS中更新OneToMany关系,javascript,typescript,nestjs,typeorm,Javascript,Typescript,Nestjs,Typeorm,类似于: 我有两个实体(书本和学生): 及 每个学生都阅读书籍,一本书可以由一个学生阅读,一旦阅读,它就被标记为这样(isRead=true)。学生一次只能阅读一本书(社区学院…),并且只能在当前一本书完成后才开始阅读下一本书(学生和书可以彼此独立存在;关系(“阅读”)稍后建立 我所尝试的: // Get all students const currentStudent = await getConnection(). getRepository(Student). createQu

类似于:

我有两个实体(书本和学生):

每个学生都阅读书籍,一本书可以由一个学生阅读,一旦阅读,它就被标记为这样(isRead=true)。学生一次只能阅读一本书(社区学院…),并且只能在当前一本书完成后才开始阅读下一本书(学生和书可以彼此独立存在;关系(“阅读”)稍后建立

我所尝试的:

// 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)