Yii 对计算字段进行筛选和排序

Yii 对计算字段进行筛选和排序,yii,Yii,你好!这样的问题。 有一个学生的表格:StudID,stud姓氏,StudLastName。。。 与分数相关的表格:PointID、PointStudFK外键、Points。 关系有很多 'points' => array(self::HAS_MANY, 'Points', array('PointStudFK' => 'StudID')) 对于每个学生,我在CGridView中带来的点数,但过滤器不起作用。 过滤器工作,但将值与学生的所有分数之和进行比较,而不是每个分数的总和 虚

你好!这样的问题。 有一个学生的表格:StudID,stud姓氏,StudLastName。。。 与分数相关的表格:PointID、PointStudFK外键、Points。 关系有很多

'points' => array(self::HAS_MANY, 'Points', array('PointStudFK' => 'StudID'))
对于每个学生,我在CGridView中带来的点数,但过滤器不起作用。 过滤器工作,但将值与学生的所有分数之和进行比较,而不是每个分数的总和

虚拟场

private $_point= null;
接二连三

getSumPoints () - function calculating the sum of scores on individual student

    public function getPoint()
    {
        if ($this->_point === null && $this->points!== null)
        {
            $this->_point = $this->points->getSumPoints($this->StudID);
        }
        return $this->_point;
    }
    public function setPoint($value)
    {
        $this->_point = $value;
    }

search()

    $criteria = new CDbCriteria;
    $criteria->together = true;
    $criteria->with = array('points'=>array(
    'select' => array('SUM(Points) as total')));
    if(!empty($this->pointExp1)) $criteria->having = "total = {$this->point}";

需要分组,但不知道如何分组。

是的,您需要一个分组依据,可能在StudID上?可能使用stat-relation,例如:'pointsSum'=>arrayself::HAS_stat,'Points',array'PointStudFK'=>'StudID',谢谢!帮助$criteria->group='points.PointStudFK';