EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
postgresql delete alias fix
Yuri Kuznetsovb71a237cad70
diff --git a/application/Espo/ORM/QueryComposer/PostgresqlQueryComposer.php b/application/Espo/ORM/QueryComposer/PostgresqlQueryComposer.phpindex 9a1d71cf5b..d9288021f2 100644--- a/application/Espo/ORM/QueryComposer/PostgresqlQueryComposer.php+++ b/application/Espo/ORM/QueryComposer/PostgresqlQueryComposer.php@@ -617,4 +617,40 @@ class PostgresqlQueryComposer extends BaseQueryComposerreturn 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;+ }}diff --git a/tests/unit/Espo/ORM/PostgresqlQueryComposerTest.php b/tests/unit/Espo/ORM/PostgresqlQueryComposerTest.phpindex 6f9bf7f2e9..247b718783 100644--- a/tests/unit/Espo/ORM/PostgresqlQueryComposerTest.php+++ b/tests/unit/Espo/ORM/PostgresqlQueryComposerTest.php@@ -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);+ }}