From 6281a965f538cfabd5726112071ef83dadccd754 Mon Sep 17 00:00:00 2001 From: Julian Vennen Date: Wed, 7 Jan 2026 12:48:33 +0100 Subject: [PATCH] Fix invalid SQL generation with empty where groups --- src/Query/Query.php | 4 ++-- test/tests/SQLTest.php | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Query/Query.php b/src/Query/Query.php index 0023752..1ad58e2 100644 --- a/src/Query/Query.php +++ b/src/Query/Query.php @@ -83,7 +83,7 @@ public function where(WhereCondition|array|WhereGroup $where): static */ public function getWhere(): WhereGroup|null { - if ($this->where) { + if ($this->where && $this->where->count() > 0) { return $this->where; } @@ -192,4 +192,4 @@ public function getLimit(): ?Limit { return $this->limit; } -} \ No newline at end of file +} diff --git a/test/tests/SQLTest.php b/test/tests/SQLTest.php index 647b627..0eb7599 100644 --- a/test/tests/SQLTest.php +++ b/test/tests/SQLTest.php @@ -30,6 +30,16 @@ public function testSelect() $this->assertEquals("SELECT * FROM `test`", $this->sql->generate($query)); } + public function testSelectEmptyWhere() + { + $query = new SelectQuery( + new WhereGroup(), + ); + $query->modelClassName = TestModel::class; + + $this->assertEquals("SELECT * FROM `test`", $this->sql->generate($query)); + } + public function testSelectWhereCondition() { $query = new SelectQuery(