Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeORM "OR" operator

I could not find any notion of OR operator neither in TypeORM docs nor in the source code. does it support it at all?

I'm trying to do perform a basic search with a repository.

db.getRepository(MyModel).find({   name : "john",   lastName: "doe" }) 

I know this generates an AND operation but I need an OR operation so SQL would look like:

name='john' OR lastName='doe' 

Am I forced to use the query builder for something basic like this?

like image 898
levansuper Avatar asked Nov 21 '18 07:11

levansuper


2 Answers

db.getRepository(MyModel).find({   where: [       { name: "john" },       { lastName: "doe" }   ] }) 

Pass an array to where

like image 174
Praveen Prasad Avatar answered Oct 02 '22 19:10

Praveen Prasad


I had the same issue, but I worked around it with the QueryBuilder.

This would be an example.

return await getRepository(MyModel)   .createQueryBuilder()   .where("name = :name OR lastName = :lastName", {     name: "john",     lastName: "doe"   })   .getMany(); 
like image 37
hwkd Avatar answered Oct 02 '22 21:10

hwkd