mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-29 07:26:05 +00:00
orm: fix insert query
This commit is contained in:
@@ -385,7 +385,7 @@ abstract class BaseQueryComposer implements QueryComposer
|
||||
$valuesQuery = $params['valuesQuery'] ?? null;
|
||||
|
||||
if ($isBySelect) {
|
||||
return '('. $this->composeSelecting($valuesQuery) . ')';
|
||||
return $this->composeSelecting($valuesQuery);
|
||||
}
|
||||
|
||||
if ($isMass) {
|
||||
|
||||
@@ -55,7 +55,7 @@ use PDOStatement;
|
||||
|
||||
require_once 'tests/unit/testData/DB/Entities.php';
|
||||
|
||||
class DBMapperTest extends \PHPUnit\Framework\TestCase
|
||||
class MapperTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected $db;
|
||||
protected $pdo;
|
||||
@@ -1150,7 +1150,8 @@ class DBMapperTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
$query =
|
||||
"INSERT INTO `post_tag` (`post_id`, `tag_id`) ".
|
||||
"(SELECT '1' AS `v0`, tag.id AS `id` FROM `tag` WHERE tag.name = 'test' AND tag.deleted = 0) ON DUPLICATE KEY UPDATE `deleted` = 0";
|
||||
"SELECT '1' AS `v0`, tag.id AS `id` FROM `tag` WHERE tag.name = 'test' AND tag.deleted = 0 ".
|
||||
"ON DUPLICATE KEY UPDATE `deleted` = 0";
|
||||
|
||||
$return = true;
|
||||
$this->mockQuery($query, $return);
|
||||
|
||||
@@ -323,6 +323,30 @@ class MysqlQueryComposerTest extends \PHPUnit\Framework\TestCase
|
||||
$this->assertEquals($expectedSql, $sql);
|
||||
}
|
||||
|
||||
public function testInsertValuesQuery1()
|
||||
{
|
||||
$selectQuery = $this->queryBuilder
|
||||
->select()
|
||||
->from('Account')
|
||||
->select('id')
|
||||
->withDeleted()
|
||||
->build();
|
||||
|
||||
$query = $this->queryBuilder
|
||||
->insert()
|
||||
->into('Account')
|
||||
->columns(['id'])
|
||||
->valuesQuery($selectQuery)
|
||||
->build();
|
||||
|
||||
$sql = $this->query->compose($query);
|
||||
|
||||
$expectedSql =
|
||||
"INSERT INTO `account` (`id`) SELECT account.id AS `id` FROM `account`";
|
||||
|
||||
$this->assertEquals($expectedSql, $sql);
|
||||
}
|
||||
|
||||
public function testInsertUpdate()
|
||||
{
|
||||
$sql = $this->query->compose(Insert::fromRaw([
|
||||
|
||||
Reference in New Issue
Block a user