[英]typeorm leftJoinAndSelect get one item of relation array
我是韓國學生。 請理解我糟糕的英語。
我正在嘗試與參與者一起獲得 chatting_room,而 chatting_room 的參與者是已登錄用戶。
這是我的代碼
await this.Repository
.createQueryBuilder("room")
.leftJoinAndSelect("room.owner", "owner")
.leftJoinAndSelect("room.matching", "matching")
.leftJoinAndSelect("room.participants", "participants")
.where("participants.userId = :userId", { userId: loggedInUser.userId })
.getMany()
chatting_room (ManyToMany) 中有兩個參與者,但結果只顯示一個已登錄的用戶,我想獲得所有參與者。 問題是什么? 請幫我 !
我現在就用這段代碼
const participatedList = await this.chatting_roomDB
.createQueryBuilder("room")
.leftJoinAndSelect("room.owner", "owner")
.leftJoinAndSelect("room.matching", "matching")
.leftJoinAndSelect("room.participants", "participants")
.where("participants.userId = :userId", { userId: loggedInUser.userId })
.getMany()
const participatedRoomIds = await participatedList.map((room) => {
return { chatting_roomId: room.chatting_roomId }
})
const participatedRooms = await this.chatting_roomDB.find({
where: participatedRoomIds,
relations: ["owner", "participants", "matching"],
})
糟糕的 !! 哈哈給我一個很好的代碼!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.