Skip to content

Commit 6281a96

Browse files
committed
Fix invalid SQL generation with empty where groups
1 parent 84bcd0f commit 6281a96

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/Query/Query.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function where(WhereCondition|array|WhereGroup $where): static
8383
*/
8484
public function getWhere(): WhereGroup|null
8585
{
86-
if ($this->where) {
86+
if ($this->where && $this->where->count() > 0) {
8787
return $this->where;
8888
}
8989

@@ -192,4 +192,4 @@ public function getLimit(): ?Limit
192192
{
193193
return $this->limit;
194194
}
195-
}
195+
}

test/tests/SQLTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ public function testSelect()
3030
$this->assertEquals("SELECT * FROM `test`", $this->sql->generate($query));
3131
}
3232

33+
public function testSelectEmptyWhere()
34+
{
35+
$query = new SelectQuery(
36+
new WhereGroup(),
37+
);
38+
$query->modelClassName = TestModel::class;
39+
40+
$this->assertEquals("SELECT * FROM `test`", $this->sql->generate($query));
41+
}
42+
3343
public function testSelectWhereCondition()
3444
{
3545
$query = new SelectQuery(

0 commit comments

Comments
 (0)