Yii Framework Forum: Fetching row from AR query - Yii Framework Forum

Jump to content

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

Fetching row from AR query Rate Topic: -----

#1 User is offline   Hudson Nguyen 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 96
  • Joined: 19-January 09
  • Location:Vietnam

Posted 31 December 2009 - 12:57 AM

I've not look deep into the AR component but still wanna ask if anyone know how to fetch row from AR query in the same way of fetching from DataReader.

For example:

$articles = Article::model()->findAll(); //I have an array of Article object

If I need to perform some modification to each object then I have to make a loop and it slows down performance. I am thinking about

$resource = Article::model()->findAll(param1, param2,....,return_raw_resource)
while(($article = $resource->read()) != false){
//modify $article's attributes
//add to an array
}

Thanks
0

#2 User is offline   Sander 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 169
  • Joined: 03-November 09
  • Location:Amsterdam, Netherlands

Posted 31 December 2009 - 07:59 AM

I don't think that can be done. CActiveRecord does have some methods for bulk updating though, and there's also afterFind(). Maybe that'll help?
0

#3 User is offline   Hudson Nguyen 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 96
  • Joined: 19-January 09
  • Location:Vietnam

Posted 31 December 2009 - 11:10 PM

View PostSander, on 31 December 2009 - 07:59 AM, said:

I don't think that can be done. CActiveRecord does have some methods for bulk updating though, and there's also afterFind(). Maybe that'll help?


Thank Sander.

For my sample code afterFind() helps partialy. In fact, as I will return the result articles to an ajax request, what I need is just the $article->attributes array. Digging Yii code ;)
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