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(