I'm building a Nest.js app with PostgresQL using TypeORM, I have entity User and entity Role, which are connected to each other with Many-to-Many relation. User has an array of roles, where each role assigned to this user is stored, but when I try to get all the users, that roles array doesn't show. Using Sequelize ORM i could get all the data from users using that code - {include: {all: true}}, example:
const users = await this.usersRepository.find({include: {all: true}})
But in TypeORM it doesn't work. I tried to find it in TypeORM docs, but I didn't find an answer. Sorry for my english, i hope you understood me.
CodePudding user response:
It seems TypeORM wait for a list of relations you want to populate : https://orkhan.gitbook.io/typeorm/docs/relational-query-builder
In your case, it could look like :
const users = await this.usersRepository.find({relations: {roles: true}})