【发布时间】:2021-12-11 10:39:20
【问题描述】:
我正在搜索和阅读文档,但找不到解决方案。
有没有办法在 TypeORM 的 find/findOne 方法中将 where 参数设置为字符串?
因为,TypeORM 似乎不接受私有属性作为 find/findOne 方法中的参数,我明白为什么。
例如,这是使用的类:
import { Column } from 'typeorm';
@Entity()
export default class Client extends BaseEntity{
...
@Column({ name: 'email', type: 'varchar', length: 64, unique: true })
private _email: string;
...
}
这是控制器功能:
...
async function testing(request: Request, response: Response, next: NextFunction) {
const { name, email, password } = request.body;
const existingClient = await Client.findOne({ _email: email });
console.log(existingClient);
}
...
我想创建类似的东西:
await Client.findOne({`email = testing@email.com`});
有没有办法做到这一点?
【问题讨论】:
-
这看起来很奇怪。为什么要在这里私有字段?也许这个开放的问题是相关的:github.com/typeorm/typeorm/issues/3548
标签: typescript typeorm