Yii Framework Forum: Activequery And Fetch Mode - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Activequery And Fetch Mode some crazy stuff

#1 User is offline   ORey 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,701
  • Joined: 20-April 09
  • Location:Moscow, Russia

Posted 05 November 2013 - 04:06 PM

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?
God is real unless declared as integer
0

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 3,788
  • Joined: 17-January 09
  • Location:Russia

Posted 06 November 2013 - 04:58 AM

I think it's not related to AR. AR always produces a model or set of models (except asArray) so I don't know what should be produced if fetch mode is different.
Yii 1.1 Application Development Cookbook

Enjoying Yii? Star us at github: 1.1 and 2.0.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users