Fixed yii\db\ActiveRecord::with() unable to use relation defined via attached behavior in case asArray is enabled

This commit is contained in:
Klimov Paul
2018-01-23 12:46:56 +02:00
parent 77bdcda5c5
commit b9cbc56330
3 changed files with 12 additions and 1 deletions

View File

@ -8,6 +8,7 @@ Yii Framework 2 Change Log
- Bug #14711: Fixed `yii\web\ErrorHandler` displaying exception message in non-debug mode (samdark)
- Enh #13814: MySQL unique index names can now contain spaces (df2)
- Bug #15300: Fixed "Cannot read property 'style' of undefined" error at the error screen (vitorarantes)
- Bug #15540: Fixed `yii\db\ActiveRecord::with()` unable to use relation defined via attached behavior in case `asArray` is enabled (klimov-paul)
- Enh #15426: Added abilitiy to create and drop database views (igravity, vladis84)
- Enh #10186: Use native `hash_equals` in `yii\base\Security::compareString()` if available, throw exception if non-strings are compared (aotd1, samdark)
- Bug #15122: Fixed `yii\db\Command::getRawSql()` to properly replace expressions (hiscaler, samdark)

View File

@ -162,7 +162,9 @@ trait ActiveQueryTrait
{
$primaryModel = reset($models);
if (!$primaryModel instanceof ActiveRecordInterface) {
$primaryModel = new $this->modelClass();
/* @var $modelClass ActiveRecordInterface */
$modelClass = $this->modelClass;
$primaryModel = $modelClass::instance();
}
$relations = $this->normalizeRelations($primaryModel, $with);
/* @var $relation ActiveQuery */

View File

@ -1600,5 +1600,13 @@ abstract class ActiveRecordTest extends DatabaseTestCase
$this->assertInstanceOf(OrderItemWithConstructor::className(), $item);
$this->assertEquals(1, $item->item_id);
// @see https://github.com/yiisoft/yii2/issues/15540
$orders = OrderWithConstructor::find()
->with(['customer.profile', 'orderItems'])
->orderBy('id')
->asArray(true)
->all();
$this->assertCount(3, $orders);
}
}