Nested $and's and $or's test
This commit is contained in:
parent
940a080e18
commit
ebca381e9b
|
@ -370,13 +370,12 @@ class InternalBuilder {
|
|||
}
|
||||
|
||||
if (filters.$and) {
|
||||
iterate(filters.$and, (key: string, conditions: any[]) => {
|
||||
const { $and } = filters
|
||||
query = query.where(x => {
|
||||
for (const condition of conditions) {
|
||||
for (const condition of $and.conditions) {
|
||||
x = this.addFilters(x, condition, table, opts)
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
if (filters.$or) {
|
||||
|
|
|
@ -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