I am trying to creating a STAT relation for a model that sums up the contents of a column provided that another column matches my conditional statement. In my particular case, I need to get the sum of all the file sizes of the pictures that a user has uploaded.
Code:
class User extends CActiveRecord {
public function relations() {
return array(
'pictureSpaceUsed'=>array(self::STAT, 'Picture', 'user_id', 'select' => 'SUM(size)','condition' => 'user_id=' . $this->id),
),
}
}
Problem is that Yii complains that it can't access the id of the model. $this->id doesn't seem to be working inside the relations function... It works if I replace $this->id with a number though, but that wouldn't be dynamic anymore.
Anybody know what's going on here?