I was searching and reading the docs, but coundn't find a solution.
Is there a way to set the where param as string in find/findOne method in TypeOrm?
Because, it seens that TypeOrm doens't accepts private attributes as a param in find/findOne methods, and I understand why.
Example, this is the class used:
import { Column } from 'typeorm';
@Entity()
export default class Client extends BaseEntity{
...
@Column({ name: 'email', type: 'varchar', length: 64, unique: true })
private _email: string;
...
}
This is the controller function:
...
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);
}
...
I thought creating something like:
await Client.findOne({`email = [email protected]`});
Is there a way to do this?
I would recommend to simply use it as public
.
When you really want to use private
, you probably need to use the entitymanager:
entityManager
.createQueryBuilder(Client, "client")
.where("client._email = :email", { email: '[email protected]' })
.getOne();
What is and how to add entityManager
: https://typeorm.io/#/working-with-entity-manager
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments