Skip to content

Commit

Permalink
Wrap createCommand for respecting \yii\db\ActiveRecord::getDb
Browse files Browse the repository at this point in the history
  • Loading branch information
Izumi-kun committed Jan 16, 2025
1 parent dcf8674 commit 442761d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 7 additions & 1 deletion framework/data/ActiveDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,14 @@ public function all($db = null)
{
return $this->wrappedQuery->populate(parent::all($db));
}
public function createCommand($db = null)
{
$command = $this->wrappedQuery->createCommand($db);
$this->from(['q' => "({$command->getSql()})"])->params($command->params);
return parent::createCommand($command->db);
}
};
$wrapper->select('*')->from(['q' => $this->query]);
$wrapper->select('*');
$wrapper->wrappedQuery = $this->query;
$wrapper->emulateExecution = $this->query->emulateExecution;

Expand Down
1 change: 0 additions & 1 deletion tests/framework/data/ActiveDataProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ public function testPaginationWithUnionQuery()
$q1 = Item::find()->where(['category_id' => 2])->with('category');
$q2 = Item::find()->where(['id' => [2, 4]]);
$provider = new ActiveDataProvider([
'db' => $this->getConnection(),
'query' => $q1->union($q2)->indexBy('id'),
]);
$pagination = $provider->getPagination();
Expand Down

0 comments on commit 442761d

Please sign in to comment.