Skip to content

Commit ff997ec

Browse files
committed
FIX DELETE rowsIn compilation
1 parent c2609f8 commit ff997ec

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/DeleteQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function getConnection()
6161

6262
public function rowsIn(string $table)
6363
{
64-
$this->rowsInArray[$table];
64+
$this->rowsInArray[] = $table;
6565
}
6666

6767
public function getRowsIn()

src/Driver/QueryCompiler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ protected function compileDelete(DeleteQuery $delete): string
152152
$query = 'DELETE FROM ';
153153
$rowsIn = $delete->getRowsIn();
154154
if (count($rowsIn) > 0) {
155-
$query = 'DELETE ' . join(',', $rowsIn) . ' FROM';
155+
$query = 'DELETE ' . join(',', $rowsIn) . ' FROM ';
156156
}
157157
$query .= $this->compileTable($delete->getTable());
158158
foreach ($delete->getJoins() as $join) {

test/DeleteQueryTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,19 @@ public function testDeleteCase()
2424
$this->assertEquals('DELETE FROM table1 WHERE key = :v1', $compiled->getQuery());
2525
$this->assertEquals(['v1' => 15], $compiled->getValues());
2626
}
27+
28+
public function testDeleteRowsIn()
29+
{
30+
$query = Query::deleteFrom(['t1' => 'table1']);
31+
$query->innerJoin(['t2' => 'table2'])
32+
->on('t2.key1', 't1.key1');
33+
$query->where('t2.filter', 3);
34+
$query->rowsIn('t1');
35+
36+
$compiled = $this->compiler->compileQuery($query);
37+
38+
$expected = 'DELETE t1 FROM table1 AS t1 INNER JOIN table2 AS t2 ON t2.key1 = t1.key1 WHERE t2.filter = :v1';
39+
$this->assertEquals($expected, $compiled->getQuery());
40+
$this->assertEquals(['v1' => 3], $compiled->getValues());
41+
}
2742
}

0 commit comments

Comments
 (0)