orm fix select item array with 1 element

This commit is contained in:
Yuri Kuznetsov
2023-05-23 14:24:43 +03:00
parent 7c729aa23f
commit 0276fcf5ce
2 changed files with 26 additions and 3 deletions
@@ -1813,9 +1813,14 @@ abstract class BaseQueryComposer implements QueryComposer
];
}
if (is_array($attribute) && count($attribute) === 2) {
$alias = $attribute[1];
if (is_array($attribute) && count($attribute) === 1) {
$attribute = $attribute[0];
}
if (is_array($attribute) && count($attribute) === 2) {
// @todo Refactor to unite convertComplexExpression and select, noSelect, notStorable (here and below).
$alias = $attribute[1];
$attribute0 = $attribute[0];
if (!$entity->hasAttribute($attribute0)) {
@@ -1848,7 +1853,7 @@ abstract class BaseQueryComposer implements QueryComposer
}
if (!is_string($attribute)) {
throw new RuntimeException();
throw new RuntimeException("Bad select.");
}
if (!$entity->hasAttribute($attribute)) {
@@ -3128,4 +3128,22 @@ class MysqlQueryComposerTest extends \PHPUnit\Framework\TestCase
$this->query->composeSelect($query)
);
}
public function testSelections1(): void
{
$query1 = SelectBuilder::create()
->select(['number'])
->from('Post')
->build();
$query2 = SelectBuilder::create()
->select($query1->getSelect())
->from('Post')
->build();
$this->assertEquals(
$this->query->composeSelect($query1),
$this->query->composeSelect($query2)
);
}
}