Skip to content

Instantly share code, notes, and snippets.

@Houserqu
Last active May 5, 2021 01:54
Show Gist options
  • Save Houserqu/eaa90675c4f1edfbfee8792d8594e771 to your computer and use it in GitHub Desktop.
Save Houserqu/eaa90675c4f1edfbfee8792d8594e771 to your computer and use it in GitHub Desktop.
typeorm

Repository 联查不支持 where,限制很多,使用 querybuild 和 leftJoinAndMapOne 方法可以将管理表作为一个属性

@Entity("record", { schema: "demo" })
export class Record {
  ...

  question: Question // 定义管理表挂载的属性
}
return await getRepository(Record)
      .createQueryBuilder('record')
      .leftJoinAndMapOne('record.question', Question, 'question', 'question.id = record.questionId')
      .where('record.tiku = :tiku and record.userId = :userId and result = 0', { tiku, userId })
      .groupBy('record.questionId')
      .getMany()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment