I am using the CDbCriteria to join two tables restaurants and tables. A restaurant can have multiple tables. I want to get the list of restaurants along with the number of tables in that particular restaurant.
I am using the following code :
$criteria = new CDbCriteria();
$criteria->select = "t.*, COUNT(t2.id) as rowCount";
$criteria->group = "t2.restaurantId";
$criteria->join = "LEFT JOIN {{tables}} t2 ON t.id = t2.restaurantId";
$criteria->condition = "t.clientId = ".Yii::app()->user->clientId;
$restaurants = Restaurants::model()->findAll($criteria);
When I try to display the value of rowCount it is showing Property "Restaurants.tableCount" is not defined. Also please tell me if this is the correct method of doing things in Yii as I am new to Yii