Nested $and's and $or's test
This commit is contained in:
parent
940a080e18
commit
ebca381e9b
|
@ -370,12 +370,11 @@ class InternalBuilder {
|
|||
}
|
||||
|
||||
if (filters.$and) {
|
||||
iterate(filters.$and, (key: string, conditions: any[]) => {
|
||||
query = query.where(x => {
|
||||
for (const condition of conditions) {
|
||||
x = this.addFilters(x, condition, table, opts)
|
||||
}
|
||||
})
|
||||
const { $and } = filters
|
||||
query = query.where(x => {
|
||||
for (const condition of $and.conditions) {
|
||||
x = this.addFilters(x, condition, table, opts)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -2850,5 +2850,48 @@ describe.each([
|
|||
},
|
||||
}).toFindNothing()
|
||||
})
|
||||
|
||||
it("can nest $and under $or filters", async () => {
|
||||
await expectQuery({
|
||||
$or: {
|
||||
conditions: [
|
||||
{
|
||||
$and: {
|
||||
conditions: [
|
||||
{
|
||||
range: { age: { low: 1, high: 8 } },
|
||||
},
|
||||
{ equal: { name: "Jan" } },
|
||||
],
|
||||
},
|
||||
equal: { name: "Jane" },
|
||||
},
|
||||
],
|
||||
},
|
||||
}).toContainExactly([
|
||||
{ age: 1, name: "Jane" },
|
||||
{ age: 8, name: "Jan" },
|
||||
])
|
||||
})
|
||||
|
||||
it("can nest $or under $and filters", async () => {
|
||||
await expectQuery({
|
||||
$and: {
|
||||
conditions: [
|
||||
{
|
||||
$or: {
|
||||
conditions: [
|
||||
{
|
||||
range: { age: { low: 1, high: 8 } },
|
||||
},
|
||||
{ equal: { name: "Jan" } },
|
||||
],
|
||||
},
|
||||
equal: { name: "Jane" },
|
||||
},
|
||||
],
|
||||
},
|
||||
}).toContainExactly([{ age: 1, name: "Jane" }])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue