Hi all,
The relation between ‘Post’ model and ‘Comment’ model is one to many, and the relations of ‘Post’ is defined as:
public function relations()
{
return array(
'comments' => array(self::HAS_MANY, 'Comment', 'postID'),
'commentCount' => array(self::STAT, 'Comment', 'Comment(postID, commentID)'),
);
}
Now, the commentCount is display in a ‘Post’ CGridView. How to write the CDbCriteria so that
the field can be searched and sorted?
I tried the following but Yii complains ‘Unknown column in SQL …’:
public function search()
{
$criteria = new CDbCriteria;
...
$criteria->with = array('commentCount');
$criteria->compare('commentCount', $this->commentCount);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}
Thanks.