使用 NestJs 从数据库中获取隐藏字段 [英] Get hidden field from database using NestJs
问题描述
我对密码应用了隐藏属性:
I applied hidden property on password:
@Column({nullable: true, select: false})
password: string;
登录时我需要提交密码.因此,根据他 documentation 我可以使用以下方法选择此隐藏值:
Doing the login i need the password filed. So according to he documentation i can select this hidden value by using:
const qb = getConnection().createQueryBuilder()
const user = await qb
.select("password", "password")
.from(User, 'user')
.where("password = :password", {
password: password
})
.addSelect('password', 'password')
.getOne()
这样做我得到 undefined
并且 password
属性仍然隐藏.
如何在我的情况下获取隐藏值?
Doing this i get undefined
and the password
property anyway remains hidden.
How to get hidden values in my situation?
推荐答案
根据文档可以选择隐藏值
According to the documentation you can select hidden value by using
.addSelect('user.password')
您有 .addSelect('password', 'password')
这将不起作用.不要为隐藏列的列设置别名.(可能是 TypeOrm 中的一个错误).
You have .addSelect('password', 'password')
which will not work. Do not alias the columns for hidden columns. (Probably a bug in TypeOrm).
这也行
.select('user.password')
对于相同的列,您不需要 select
和 addSelect
,addSelect
什么都不做,因为已经选择了这些列.
You don't need both select
and addSelect
for the same columns, the addSelect
does nothing since the columns are already selected.
这篇关于使用 NestJs 从数据库中获取隐藏字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!