Average Relations

Hey

I want to calculate the average of a certain column in a table. Does anybody know how I can define it in the relations?

‘RatingAvg’=>array(self::STAT,…?

Thx!

You can use MySql AVG aggregate functions. You need to define a relationship in you main model to the Rating model. Rating model has a foreign key to main model called main_model_id:





'rating' => array(self::STAT, 'Rating', 'main_model_id',

                        'select' =>'ROUND(AVG(rating))',

                        'group' => 'main_model_id',

                ),



More functions are available here.

Thx!