orm fix select item array with 1 element
This commit is contained in:
@@ -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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user