postgresql delete alias fix
This commit is contained in:
@@ -617,4 +617,40 @@ class PostgresqlQueryComposer extends BaseQueryComposer
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function composeDeleteQuery(
|
||||
string $table,
|
||||
?string $alias,
|
||||
string $where,
|
||||
?string $joins,
|
||||
?string $order,
|
||||
?int $limit
|
||||
): string {
|
||||
|
||||
$sql = "DELETE ";
|
||||
|
||||
$sql .= "FROM " . $this->quoteIdentifier($table);
|
||||
|
||||
if ($alias) {
|
||||
$sql .= " AS " . $this->quoteIdentifier($alias);
|
||||
}
|
||||
|
||||
if ($joins) {
|
||||
$sql .= " $joins";
|
||||
}
|
||||
|
||||
if ($where) {
|
||||
$sql .= " WHERE $where";
|
||||
}
|
||||
|
||||
if ($order) {
|
||||
$sql .= " ORDER BY $order";
|
||||
}
|
||||
|
||||
if ($limit !== null) {
|
||||
$sql = $this->limit($sql, null, $limit);
|
||||
}
|
||||
|
||||
return $sql;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,4 +347,23 @@ class PostgresqlQueryComposerTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
$this->assertEquals($expectedSql, $sql);
|
||||
}
|
||||
|
||||
public function testDeleteWithAlias()
|
||||
{
|
||||
$query = $this->queryBuilder
|
||||
->delete()
|
||||
->from('Account', 'a')
|
||||
->where([
|
||||
'a.name' => 'test',
|
||||
])
|
||||
->build();
|
||||
|
||||
$sql = $this->queryComposer->compose($query);
|
||||
|
||||
$expectedSql =
|
||||
"DELETE FROM \"account\" AS \"a\" " .
|
||||
"WHERE \"a\".\"name\" = 'test'";
|
||||
|
||||
$this->assertEquals($expectedSql, $sql);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user