I have a model Reporter.
public function relations() {
return array(
'video' => array(self::HAS_MANY, 'Video', 'reporter_id'),
);
}
I have a mysql query for Reporter->search() method:
SELECT t.*, COUNT(t1.id) AS 'reports'
FROM reporter AS t
LEFT JOIN video AS t1 ON t.id = t1.reporter_id
GROUP BY t.id
ORDER BY t.name
How can it be written in terms of CDbCriteria to use with CActiveDataProvider?
To write that query into the criteria for a CActiveDataProvider you’ll need to set the following properties from CDbCriteria:
select,
join,
group, and
order.
You can then set them while creating a new CActiveDataProvider object like so:
The whole list of properties and methods that you can use with CDbCriteria can be found here: CDbCriteria Class Reference