0

How in yii 1.1.7 using CDbCriteria and CActiveDataProvider to make subquery for calculaion number of rows in related table in 1 request ?

In CodeIgniter I wrote like :

$CategoryFactory = ORM::factory('category');
$CategoryFactory->select( DB::expr(  ' ( select count(*) from `tour` where `tour`.`category_id` = `category`.`id` ) as related_tours_count ' ) );      
...
$category_result= $CategoryFactory->find_all();

Is there is similar way in yii 1.1.7 ?

user2339232
  • 757
  • 3
  • 11
  • 22

1 Answers1

0

I never used codeIgniter, but in Yii must define a Model and then use countBySql method or any other method of the CActiveRecord class