system
(system)
1
Hi all
I've met one little problem:
<?php $record = Record::model()->findByPk($id);
The code above will fetch all record attributes, but what if I don't need them all?
Actually I need the single attribute and I have no need to get all the attributes from database. It decreases performance as you know.
Can anyone help me with this point? I’m sure that a solution exists, but it is not clear to me…
schrenzor
(Rene Ponudic)
2
Hy there,
take a look at the database - section in "the definitive guide to Yii"…
http://www.yiiframew…ide/database.ar
You could define the attribute you need in the select property of your DB - criteria and use find() instead of findByPk()
$criteria = new CDbCriteria;
$criteria->select = 'ATTRIBUTE_NAME';
$criteria->condition = 'id=:id';
$criteria->params = array('id'=>10);
Hope this helps you…
system
(system)
3
Thanks a lot!
I still haven't check it, but I think that is obviously what I actually need.