nestjs typeorm / How to find row with many to many relation column?


chatting_room.entity.ts


@InputType("Chatting_Room", { isAbstract: true })
@ObjectType()
@Entity()
export class Chatting_Room {
//...
@ManyToMany((type) => User, (user) => user.chatting_rooms, {
    nullable: true,
    onDelete: "SET NULL",
  })
  @Field((type) => [User], { nullable: true })
  participants: User[]
//...
}

chatting_rooms.resolver.ts

@Resolver((of) => Chatting_Room)
export class Chatting_RoomsResolver {
  constructor(private readonly chatting_roomsService: Chatting_RoomsService) {}
// ...
 @Query((returns) => Chatting_Room_List_Output)
  chatthing_room_list(
    @LoggedInUser() loggedInUser: User,
  ): Promise<Chatting_Room_List_Output> {
    return this.chatting_roomsService.chatting_room_list(loggedInUser)
  }
// ...
}

chatting_rooms.service.ts

@Injectable()
export class Chatting_RoomsService {
  constructor(
    @InjectRepository(Chatting_Room)
    private readonly chatting_roomDB: Repository<Chatting_Room>,

    @InjectRepository(User)
    private readonly userDB: Repository<User>,
  ) {}

//...
async chatting_room_list(
    loggedInUser: User,
  ): Promise<Chatting_Room_List_Output> {
    try {
      if (!loggedInUser) {
        return {
          ok: false,
          error: "###",
        }
      }

      const ownedChattingRooms = await this.chatting_roomDB.find({
        where: { owner: loggedInUser },
        relations: ["owner", "chattings"],
      })
// -------------------------here----------------------------------
      const participatedRooms = await this.chatting_roomDB.find({
        where: { participants: [loggedInUser] }, 
      })
// -------------------------here----------------------------------
    } catch (e) {
      return {
        ok: false,
        error: e.message,
      }
    }
  }
//...

}

I want to find chatting room row with participants but
I got error message "Cannot query across many-to-many for property participants"
how can i find that row?

my english so bad because i am korean.
can u use easy english for me ?

Source: JavaSript – Stack Overflow

November 17, 2021
Category : News
Tags: javascript | nestjs | typeorm | typescript

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.