Skip to content

Commit 521a61d

Browse files
committed
refactor(nested): handle empty query array case
- Added check for empty query array in toArray method - Ensured a default 'bool' structure is returned when no queries exist
1 parent b1bf7b5 commit 521a61d

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/Query/Nested.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,19 @@ public function key(): string
3232

3333
public function toArray(): array
3434
{
35+
$queryArray = $this->query->toArray();
36+
37+
if (count($queryArray) === 0) {
38+
$queryArray = [
39+
'bool' => [],
40+
];
41+
}
42+
3543
return [
3644
'nested' => [
3745
'path' => $this->path,
3846
'query' => [
39-
'bool' => $this->query->toArray(),
47+
$queryArray,
4048
],
4149
],
4250
];

0 commit comments

Comments
 (0)