Reputation: 85
I'd like to achieve something like this:
WHERE ( statement1 OR statement2 ) AND statement3
How can I achieve this with query builder?
I have tried this before:
Entity.createQueryBuilder()
.where(statement1)
.orWhere(statement2)
.andWhere(statement3);
But it produces following query:
WHERE statement1 OR statement2 AND statement3
Upvotes: 3
Views: 411
Reputation: 59
I believe that if @sp Kruten answer doesn't suit you, you'll find something here.
Upvotes: 1
Reputation: 85
I have figured it out myself, basically you should use Brackets
from typeorm:
Entity.createQueryBuilder()
.where(
new Brackets((qb1) => {
qb1.where(statement1).orWhere(statement2);
})
)
.andWhere(statement3);
Upvotes: 4