Typeorm - 左连接并仅选择关系实体 [英] Typeorm - left join and select only relation entity
本文介绍了Typeorm - 左连接并仅选择关系实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有命令:
.leftJoinAndSelect("permission.user", "user").where("permission.stream = :stream", {stream: req.params.id}).getMany();
这给了我这个输出:
<预><代码>[允许 {编号:51,用户:用户{昵称:'jmat',密码:'jmat',电子邮件:'jmat@nothing.com'}}]我只想要这样的输出:
<预><代码>[用户 { 昵称:'jmat',密码:'jmat',电子邮件:'jmat@nothing.com'}}]我尝试将这样的行添加到 where 和 getMany 之间的代码中,但它不起作用.也试过使用joinAndMap,但都没有解决.
.select(['user']).select(['permission.user']
感谢您的帮助
解决方案
尝试带有 select
和 getRawMany
.leftJoinAndSelect("permission.user", "user").where("permission.stream = :stream", {stream: req.params.id}).select(用户").getRawMany();
I have command:
.leftJoinAndSelect("permission.user", "user")
.where("permission.stream = :stream", {stream: req.params.id})
.getMany();
Which gives me this output:
[
Permission {
id: 51,
user: User { nick: 'jmat', password: 'jmat', email: 'jmat@nothing.com' }
}
]
I want only output like this:
[
User { nick: 'jmat', password: 'jmat', email: 'jmat@nothing.com' }
}
]
I tried to add rows like this to my code between where and getMany, but it doesnt work. Also tried to use joinAndMap, but didnt solve it neither.
.select(['user'])
.select(['permission.user']
Thank you for your help
解决方案
Try the option with select
and getRawMany
.leftJoinAndSelect("permission.user", "user")
.where("permission.stream = :stream", {stream: req.params.id})
.select("user")
.getRawMany();
这篇关于Typeorm - 左连接并仅选择关系实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文