Commit 1b4a9b62 by Qiang Xue

Fixes #3568: When the primary query sets `asArray`, it is not respected by the…

Fixes #3568: When the primary query sets `asArray`, it is not respected by the `via` relational query
parent 7c2be495
......@@ -39,6 +39,7 @@ Yii Framework 2 Change Log
- Bug #3559: Use native support for batchInsert in SQLite versions >= 3.7.11 and avoid limitations of the fallback (cebe)
- Bug #3564: Fixed the bug that primary key columns should not take default values from schema (qiangxue)
- Bug #3567: Fixed the bug that smallint was treated as string for PostgreSQL (qiangxue)
- Bug #3568: When the primary query sets `asArray`, it is not respected by the `via` relational query (qiangxue)
- Bug #3578: Fixed postgreSQL column type detection, added missing types (MDMunir, cebe)
- Bug #3583: Added typecast to auto value of primary key on insert of sql active record (cebe)
- Bug #3591: Fixed incomplete obsolete filling in i18n `MessageController::saveMessagesToDb()` (advsm)
......
......@@ -203,8 +203,12 @@ trait ActiveRelationTrait
$this->filterByModels($viaModels);
} elseif (is_array($this->via)) {
// via relation
/* @var $viaQuery ActiveRelationTrait */
/* @var $viaQuery ActiveRelationTrait|ActiveQueryTrait */
list($viaName, $viaQuery) = $this->via;
if ($viaQuery->asArray === null) {
// inherit asArray from primary query
$viaQuery->asArray($this->asArray);
}
$viaQuery->primaryModel = null;
$viaModels = $viaQuery->populateRelation($viaName, $primaryModels);
$this->filterByModels($viaModels);
......
......@@ -121,6 +121,9 @@ class ActiveRecordTest extends DatabaseTestCase
$order = Order::findOne(2);
$this->assertEquals(2, $order->id);
$this->assertEquals(0, count($order->books));
$order = Order::find()->where(['id' => 1])->asArray()->one();
$this->assertTrue(is_array($order));
}
public function testFindEagerViaTable()
......@@ -146,6 +149,7 @@ class ActiveRecordTest extends DatabaseTestCase
// https://github.com/yiisoft/yii2/issues/1402
$orders = Order::find()->with('books')->orderBy('id')->asArray()->all();
$this->assertEquals(3, count($orders));
$this->assertTrue(is_array($orders[0]['orderItems'][0]));
$order = $orders[0];
$this->assertTrue(is_array($order));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment