admin管理员组文章数量:1395744
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.
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.
Share Improve this question edited Aug 5, 2022 at 8:56 nevermind1727 asked Aug 5, 2022 at 8:54 nevermind1727nevermind1727 231 gold badge1 silver badge4 bronze badges1 Answer
Reset to default 3It 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}})
本文标签: javascriptHow to get all the data from tables using TypeORMStack Overflow
版权声明:本文标题:javascript - How to get all the data from tables using TypeORM? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744626713a2616302.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论