Hi guys.
Wouldn’t it be cool if ActiveQuery supported fetch mode setting?
Here’s the thing: \yii\db\Command already has this support at queryAll and queryOne.
So if we just add
public $fetchMode;
to Query, and modify Query and ActiveQuery slightly
queryAll() -> queryAll($this->fetchMode);
queryOne() -> queryOne($this->fetchMode);
We’ll probably require a setter also:
public function fetchMode($fetchMode = null)
{
$this->asArray = true;
$this->fetchMode = $fetchMode;
return $this;
}
And here we go:
$listData = Model::find()->myScope()->myAnotherScope()->select(['id', 'name'])->fetchMode(\PDO::FETCH_KEY_PAIR)->all();
What do you think?