Cdbcriteria: Select Sql Calculated Column

Hi.

I need to perform the following query:


SELECT EXTRACT(HOUR FROM inizio) AS ora, COUNT(*) AS numero  FROM `navigazione` `t` WHERE inizio >= '2013-11-20' AND DATE(inizio) < DATE(NOW())  GROUP BY EXTRACT(HOUR FROM inizio)

Initially I did that with ->createCommand and was working great, but this escapes from the defaultScope() I defined into the Navigazione AR. So I converted to CDbCriteria this way:


        $cdb = new CDbCriteria();

        $cdb->select = "EXTRACT(HOUR FROM inizio) AS ora, COUNT(*) AS numero ";

        $cdb->condition = "inizio >= :data AND DATE(inizio) < DATE(NOW()) ";

        $cdb->params = array(':data'=>$d->format("Y-m-d"));

        $cdb->group = "EXTRACT(HOUR FROM inizio)";

        $ar = Navigazione::model()->findAll($cdb);

and the resulting sql is correct, but then I’ve a problem: when I cycle the $ar results I have not understand how to access “ora” or “numero” values!

Any idea? thanks

Just found out you need to add two public variables in the model


public $ora;

public $numero;