CDbCriteria Error

Hi,

I am new to Yii and am trying out the CDbCriteria command. My query is



$criteria=new CDbCriteria;


$criteria->group = 'unit.supplier_id';


$criteria->join = 'left join unit where unit.supplier_id = supplier.id';


$criteria->select = 'supplier.*, count(supplier_id) as unitcount';


$supplierList=Supplier::model()->findAll($criteria);


This produces the sql code



SELECT supplier.*, count(supplier_id) as unitcount FROM 'Supplier' left join unit where unit.supplier_id = supplier.id GROUP BY unit.supplier_id LIMIT 10


My problem is how to access the unitcount element of the resultset. When I try to access this in the view as follows



   <td><?php echo CHtml::encode($model->unitcount); ?></td>


I get the following error

[tt]

CException

Description

Property "Supplier.unitcount" is not defined.

[/tt]

ActiveRecord is looking for a model attribute named unitcount, which of course doesn't exist. So how do I access resultset named elements such as that shown above.

Thanks.

Aiden.

Declare a public member in the AR class named unitcount.

qiang

Thanks for the quick reply. That worked fine.

PS> I come from a Java/J2EE/Grails background and this is my first PHP project. So far I am very impressed with Yii. Congratulations on a great framework.

Aiden.