Skip to content

Commit

Permalink
fix: invalid DELETE query when builder uses table alias
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Jul 11, 2022
1 parent dd279db commit bd5ac24
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2363,7 +2363,7 @@ public function delete($where = '', ?int $limit = null, bool $resetData = true)
return false; // @codeCoverageIgnore
}

$sql = $this->_delete($table);
$sql = $this->_delete($this->removeAlias($table));

if (! empty($limit)) {
$this->QBLimit = $limit;
Expand Down
14 changes: 14 additions & 0 deletions tests/system/Database/Builder/DeleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ public function testGetCompiledDelete()
$this->assertSame($expectedSQL, $sql);
}

public function testGetCompiledDeleteWithTableAlias()
{
$builder = $this->db->table('jobs j');

$builder->where('id', 1);
$sql = $builder->getCompiledDelete();

$expectedSQL = <<<'EOL'
DELETE FROM "jobs"
WHERE "id" = 1
EOL;
$this->assertSame($expectedSQL, $sql);
}

public function testGetCompiledDeleteWithLimit()
{
$builder = $this->db->table('jobs');
Expand Down

0 comments on commit bd5ac24

Please sign in to comment.