0
votes

I am Korean student. please understand my bad english.

I am trying to get chatting_room with participants and the chatting_room have participant who is loggedInUser.

here is my code

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

there are two participants in chatting_room ( ManyToMany) but result show me only one that is loggedInUser I want to get all participants . what is the problem ? please help me !

1

1 Answers

0
votes

I just use this code right now

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"],
      })

terrible !! haha give me a good and nice code !!