Reputation: 1177
Precondition: I'm using Typeorm to perform database queries and I can't use the queryBuilder
methods to create this query, but only the find
method.
I need to translate a query like:
SELECT * FROM address where zip = 123 and (street = 'asd' or city = 'New York');
I know that the solution can be trivial using the usual queryBuilder
, but in this particular case I cannot use it.
Is it possible to implement these nested and/or conditions only using the find
method?
Upvotes: 3
Views: 209
Reputation: 5972
Can you please try this?
Address.find([{
zip: 123, street: 'asd'
}, {
zip: 123, city: 'New York'
}]);
if you have just and
, or
conditions, yes! it's possible to implement the query only with find
method.
In typeorm
query, you can represent or
with the array of the conditions.
zip = 123 and (street = 'asd' or city = 'New York')
is same as
(zip = 123 and street = 'asd') or (zip = 123 and city = 'New York')
Upvotes: 2