Im new to Yii and ActiveRecord and have been playing around with the Yii::app()->db->createCommand() method. Also, I’m studying for the MySQL certifications exam so I want to practice creating queries.
The queries return arrays for tables and I was wondering what is the proper way to create an AR object from this data? I see that CActiveRecord has a method called populateRecord(). However, some of my custom methods don’t work because all the attributes aren’t set (I’m assuming the ones that don’t have rules). If I use setAttributes() my methods work. Just wondering if this method is ok to use? Also, is there any more of a performance hit constructing AR objects myself versus Yii constructing them? Heres what I’m doing for now:
$cmd = Yii::app()->db->createCommand($q);
$result = $cmd->query();
echo 'Total Objects: ' , count($result);
$filesArray = array();
foreach($result as $row):
$file = new File;
$file->setAttributes($row, FALSE);
$filesArray[] = $file;
endforeach;
die(pr($filesArray));